From reebalazs at codespeak.net Mon Jan 1 14:23:57 2007 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Mon, 1 Jan 2007 14:23:57 +0100 (CET) Subject: [z3-checkins] r36090 - z3/jsonserver/branch/merge/concatresource/compression/thirdparty Message-ID: <20070101132357.2755D1007F@code0.codespeak.net> Author: reebalazs Date: Mon Jan 1 14:23:54 2007 New Revision: 36090 Modified: z3/jsonserver/branch/merge/concatresource/compression/thirdparty/packer.py Log: Update javascript packer Modified: z3/jsonserver/branch/merge/concatresource/compression/thirdparty/packer.py ============================================================================== --- z3/jsonserver/branch/merge/concatresource/compression/thirdparty/packer.py (original) +++ z3/jsonserver/branch/merge/concatresource/compression/thirdparty/packer.py Mon Jan 1 14:23:54 2007 @@ -326,7 +326,7 @@ self.protect(r"""\s+(\/[^\/\n\r\*][^\/\n\r]*\/g?i?)""") self.protect(r"""([^\w\$\/'"*)\?:]\/[^\/\n\r\*][^\/\n\r]*\/g?i?)""") # multiline comments - self.sub(r'/\*.*?\*/', '', re.DOTALL) + self.sub(r'/\*(?!@).*?\*/', '', re.DOTALL) # one line comments self.sub(r'\s*//.*$', '', re.MULTILINE) # strip whitespace at the beginning and end of each line From reebalazs at codespeak.net Mon Jan 1 15:31:10 2007 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Mon, 1 Jan 2007 15:31:10 +0100 (CET) Subject: [z3-checkins] r36093 - z3/jsonserver/branch/merge/concatresource/compression/thirdparty Message-ID: <20070101143110.0B9DD1007F@code0.codespeak.net> Author: reebalazs Date: Mon Jan 1 15:31:05 2007 New Revision: 36093 Modified: z3/jsonserver/branch/merge/concatresource/compression/thirdparty/packer.py Log: Update javascript compression to newest packer.py Modified: z3/jsonserver/branch/merge/concatresource/compression/thirdparty/packer.py ============================================================================== --- z3/jsonserver/branch/merge/concatresource/compression/thirdparty/packer.py (original) +++ z3/jsonserver/branch/merge/concatresource/compression/thirdparty/packer.py Mon Jan 1 15:31:05 2007 @@ -1,7 +1,7 @@ # # packer.py # -# Copyright (c) 2006 Florian Schulze +# Copyright (c) 2006-2007 Florian Schulze # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to @@ -21,7 +21,7 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. -import re +import re, unittest, textwrap class KeywordMapper: @@ -368,44 +368,554 @@ self.protect(r'''("(?:\\"|\\\n|.)*?")''') # strip whitespace self.sub(r'^[ \t\r\f\v]*(.*?)[ \t\r\f\v]*$', r'\1', re.MULTILINE) - # remove comment contents - self.sub(r'/\*.*?( ?[\\/*]*\*/)', r'/*\1', re.DOTALL) - # remove lines with comments only (consisting of stars only) - self.sub(r'^/\*+\*/$', '', re.MULTILINE) + if level == 'full': + # remove comments + self.sub(r'/\*.*? ?[\\/*]*\*/', r'', re.DOTALL) + #remove more whitespace + self.sub(r'\s*([{,;:])\s+', r'\1') + else: + # remove comment contents + self.sub(r'/\*.*?( ?[\\/*]*\*/)', r'/*\1', re.DOTALL) + # remove lines with comments only (consisting of stars only) + self.sub(r'^/\*+\*/$', '', re.MULTILINE) # excessive newlines self.sub(r'\n+', '\n') # first newline self.sub(r'^\n', '') - if level == 'full': - #remove more whitespace - self.sub(r'([{,;])\s+', r'\1') -## jspacker = JavascriptPacker('safe') -## jspacker_full = JavascriptPacker('full') +# be aware that the initial indentation gets removed in the following tests, +# the inner indentation is preserved though (see textwrap.dedent) +js_compression_tests = ( + ( + 'standardJS', + """\ + /* a comment */ + + function dummy() { + + var localvar = 10 // one line comment + + document.write(localvar); + return 'bar' + } + """, + """\ + function dummy(){var localvar=10 + document.write(localvar);return 'bar'} + """, + 'safe' + ), + ( + 'standardJS', + """\ + /* a comment */ + + function dummy() { + + var localvar = 10 // one line comment + + document.write(localvar); + return 'bar' + } + """, + """\ + function dummy(){var localvar=10 + document.write(localvar);return'bar'}""", + 'full' + ), + ( + 'stringProtection', + """ + var leafnode = this.shared.xmldata.selectSingleNode('//*[@selected]'); + var portal_url = 'http://127.0.0.1:9080/plone'; + """, + """var leafnode=this.shared.xmldata.selectSingleNode('//*[@selected]');var portal_url='http://127.0.0.1:9080/plone';""" + ), + ( + 'newlinesInStrings', + r"""var message = "foo: " + foo + "\nbar: " + bar;""", + r"""var message="foo: "+foo+"\nbar: "+bar;""" + ), + ( + 'escapedStrings', + r"""var message = "foo: \"something in quotes\"" + foo + "\nbar: " + bar;""", + r"""var message="foo: \"something in quotes\""+foo+"\nbar: "+bar;""" + ), + ( + 'whitspaceAroundPlus', + """\ + var message = foo + bar; + message = foo++ + bar; + message = foo + ++bar; + """, + """\ + var message=foo+bar;message=foo++ +bar;message=foo+ ++bar;""" + ), + ( + 'whitspaceAroundMinus', + """\ + var message = foo - bar; + message = foo-- - bar; + message = foo - --bar; + """, + """\ + var message=foo-bar;message=foo-- -bar;message=foo- --bar;""" + ), + ( + 'missingSemicolon', + """\ + var x = function() { + + } /* missing ; here */ + next_instr; + """, + """\ + var x=function(){} + next_instr;""", + 'safe' + ), + # be aware that the following produces invalid code. You *have* to add + # a semicolon after a '}' followed by a normal instruction + ( + 'missingSemicolon', + """\ + var x = function() { + + } /* missing ; here */ + next_instr; + """, + """\ + var x=function(){}next_instr;""", + 'full' + ), + # excessive semicolons after curly brackets get removed + ( + 'nestedCurlyBracketsWithSemicolons', + """\ + function dummy(a, b) { + if (a > b) { + do something + } else { + do something else + }; + }; + next_instr; + """, + """\ + function dummy(a,b){if(a>b){do something} else{do something else}};next_instr;""", + 'safe' + ), + ( + 'nestedCurlyBracketsWithSemicolons', + """\ + function dummy(a, b) { + if (a > b) { + do something + } else { + do something else + }; + }; + next_instr; + """, + """\ + function dummy(a,b){if(a>b){do something}else{do something else}};next_instr;""", + 'full' + ), +) + + +css_safe_compression_tests = ( + ( + 'commentCompression', + """ + /* this is a comment */ + #testElement { + property: value; /* another comment */ + } + /**********/ + /* this is a multi + line comment */ + #testElement { + /* yet another comment */ + property: value; + } + """, + """\ + /* */ + #testElement { + property: value; /* */ + } + /* */ + #testElement { + /* */ + property: value; + } + """ + ), + ( + 'newlineCompression', + """ + + + /* this is a comment */ + + #testElement { + property: value; /* another comment */ + } + + /* this is a multi + line comment */ + #testElement { + + /* yet another comment */ + property: value; + + } + + + """, + """\ + /* */ + #testElement { + property: value; /* */ + } + /* */ + #testElement { + /* */ + property: value; + } + """ + ), + # see http://www.dithered.com/css_filters/index.html + ( + 'commentHacks1', + """ + #testElement { + property/**/: value; + property/* */: value; + property /**/: value; + property: /**/value; + } + """, + """\ + #testElement { + property/**/: value; + property/* */: value; + property /**/: value; + property: /**/value; + } + """ + ), + ( + 'commentHacks2', + """ + selector/* */ { } + """, + """\ + selector/* */ { } + """ + ), + ( + 'commentHacks3', + """ + selector/* foobar */ { } + """, + """\ + selector/* */ { } + """ + ), + ( + 'commentHacks4', + """ + selector/**/ { } + """, + """\ + selector/**/ { } + """ + ), + ( + 'commentHacks5', + """ + /* \*/ + rules + /* */ + """, + """\ + /* \*/ + rules + /* */ + """ + ), + ( + 'commentHacks6', + """ + /* foobar \*/ + rules + /* */ + """, + """\ + /* \*/ + rules + /* */ + """ + ), + ( + 'commentHacks7', + """ + /*/*/ + rules + /* */ + """, + """\ + /*/*/ + rules + /* */ + """ + ), + ( + 'commentHacks8', + """ + /*/*//*/ + rules + /* */ + """, + """\ + /*/*//*/ + rules + /* */ + """ + ), + ( + 'stringProtection', + """ + /* test string protection */ + #selector, + #another { + content: 'foo; bar'; + } + """, + """\ + /* */ + #selector, + #another { + content: 'foo; bar'; + } + """ + ), +) + +css_full_compression_tests = ( + ( + 'commentCompression', + """ + /* this is a comment */ + #testElement { + property: value; /* another comment */ + } + /**********/ + /* this is a multi + line comment */ + #testElement { + /* yet another comment */ + property: value; + } + """, + """\ + #testElement{property:value;} + #testElement{property:value;} + """ + ), + ( + 'newlineCompression', + """ + + + /* this is a comment */ + + #testElement { + property: value; /* another comment */ + } + + /* this is a multi + line comment */ + #testElement { + + /* yet another comment */ + property: value; + + } + + + """, + """\ + #testElement{property:value;} + #testElement{property:value;} + """ + ), + # see http://www.dithered.com/css_filters/index.html + # in full compression all hacks get removed + ( + 'commentHacks1', + """ + #testElement { + property/**/: value; + property/* */: value; + property /**/: value; + property: /**/value; + } + """, + """\ + #testElement{property:value;property:value;property:value;property:value;} + """ + ), + ( + 'commentHacks2', + """ + selector/* */ { } + """, + """\ + selector{} + """ + ), + ( + 'commentHacks3', + """ + selector/* foobar */ { } + """, + """\ + selector{} + """ + ), + ( + 'commentHacks4', + """ + selector/**/ { } + """, + """\ + selector{} + """ + ), + ( + 'commentHacks5', + """ + /* \*/ + rules + /* */ + """, + """\ + rules + """ + ), + ( + 'commentHacks6', + """ + /* foobar \*/ + rules + /* */ + """, + """\ + rules + """ + ), + ( + 'commentHacks7', + """ + /*/*/ + rules + /* */ + """, + """\ + rules + """ + ), + ( + 'commentHacks8', + """ + /*/*//*/ + rules + /* */ + """, + """\ + rules + """ + ), + ( + 'stringProtection', + """ + /* test string protection and full compression */ + #selector, + #another { + content: 'foo; bar'; + } + """, + """\ + #selector,#another{content:'foo; bar';} + """ + ), +) + +class PackerTestCase(unittest.TestCase): + def __init__(self, name, input, output, packer): + unittest.TestCase.__init__(self) + self.name = name + self.input = input + self.output = output + self.packer = packer + + def __str__(self): + return self.name + + def runTest(self): + self.assertEqual(self.packer.pack(self.input), self.output) + + +def test_suite(): + suite = unittest.TestSuite() + + jspacker = { + 'safe': JavascriptPacker('safe'), + 'full': JavascriptPacker('full'), + } + csspacker = { + 'safe': CSSPacker('safe'), + 'full': CSSPacker('full'), + } + + for info in js_compression_tests: + name = info[0] + input = textwrap.dedent(info[1]) + output = textwrap.dedent(info[2]) + if (len(info) == 4): + compression = info[3].split(",") + else: + compression = ("safe", "full") + + for packer in compression: + suite.addTest(PackerTestCase("%s (%s)" % (name, packer), + input, output, + jspacker[packer])) + + packer = "safe" + for name, input, output in css_safe_compression_tests: + input = textwrap.dedent(input) + output = textwrap.dedent(output) + + suite.addTest(PackerTestCase("%s (%s)" % (name, packer), + input, output, + csspacker[packer])) + + packer = "full" + for name, input, output in css_full_compression_tests: + input = textwrap.dedent(input) + output = textwrap.dedent(output) + + suite.addTest(PackerTestCase("%s (%s)" % (name, packer), + input, output, + csspacker[packer])) -## def run(): - ## script = open('cssQuery.js').read() - ## script = jspacker_full.pack(script) - ## open('output.js','w').write(script) - ## mapper = JavascriptKeywordMapper() - ## mapper.analyse(script) - ## keywords = mapper.getKeywords() - ## script = mapper.sub(script) - ## f = open('output1.js','w') - ## #f.write("keywords='%s'.split('|');\n" % "|".join(keywords)) - ## #f.write(mapper.getDecodeFunction(name='__dEcOdE')) - ## f.write(mapper.getDecoder(script)) - ## for index, keyword in enumerate(keywords): - ## encoded = mapper._encode(index) - ## if keyword == '': - ## replacement = encoded - ## else: - ## replacement = keyword - ## regexp = re.compile(r'\b%s\b' % encoded) - ## script = regexp.sub(lambda m: replacement, script) - ## open('output2.js','w').write(script) + return suite -## if __name__=='__main__': - ## run() +if __name__ == '__main__': + unittest.main(defaultTest='test_suite') From ltucker at codespeak.net Wed Jan 3 02:58:18 2007 From: ltucker at codespeak.net (ltucker at codespeak.net) Date: Wed, 3 Jan 2007 02:58:18 +0100 (CET) Subject: [z3-checkins] r36114 - z3/deliverance/trunk/deliverance Message-ID: <20070103015818.29E1810064@code0.codespeak.net> Author: ltucker Date: Wed Jan 3 02:58:16 2007 New Revision: 36114 Modified: z3/deliverance/trunk/deliverance/proxyapp.py Log: add missing quote Modified: z3/deliverance/trunk/deliverance/proxyapp.py ============================================================================== --- z3/deliverance/trunk/deliverance/proxyapp.py (original) +++ z3/deliverance/trunk/deliverance/proxyapp.py Wed Jan 3 02:58:16 2007 @@ -56,7 +56,7 @@ class DebugHeaders(object): translate_keys = {'CONTENT_LENGTH': 'HTTP_CONTENT_LENGTH', - 'CONTENT_TYPE': 'HTTP_CONTENT_TYPE} + 'CONTENT_TYPE': 'HTTP_CONTENT_TYPE'} def __init__(self, app): self.app = app From kobold at codespeak.net Thu Jan 4 10:42:43 2007 From: kobold at codespeak.net (kobold at codespeak.net) Date: Thu, 4 Jan 2007 10:42:43 +0100 (CET) Subject: [z3-checkins] r36140 - z3/sqlos/branch/kobold-sqlos/src/sqlos Message-ID: <20070104094243.C5B8110070@code0.codespeak.net> Author: kobold Date: Thu Jan 4 10:42:42 2007 New Revision: 36140 Modified: z3/sqlos/branch/kobold-sqlos/src/sqlos/configure.zcml Log: Modified configure.zcml to adapt psycopg2 connections. Modified: z3/sqlos/branch/kobold-sqlos/src/sqlos/configure.zcml ============================================================================== --- z3/sqlos/branch/kobold-sqlos/src/sqlos/configure.zcml (original) +++ z3/sqlos/branch/kobold-sqlos/src/sqlos/configure.zcml Thu Jan 4 10:42:42 2007 @@ -146,6 +146,15 @@ /> + + + + Author: ltucker Date: Thu Jan 4 19:27:03 2007 New Revision: 36155 Modified: z3/deliverance/trunk/deliverance/faketestingapps.py z3/deliverance/trunk/deliverance/utils.py Log: allow spaces inside CSS urls, update faketestingapps examples Modified: z3/deliverance/trunk/deliverance/faketestingapps.py ============================================================================== --- z3/deliverance/trunk/deliverance/faketestingapps.py (original) +++ z3/deliverance/trunk/deliverance/faketestingapps.py Thu Jan 4 19:27:03 2007 @@ -21,7 +21,7 @@ Usage:: [filter-app:switchedapp] - paste.filter_app_factory = deliverance.faketestingapps.Switcher + paste.filter_app_factory = deliverance.faketestingapps:Switcher /bad_content.html = 10 next = static @@ -61,7 +61,7 @@ Usage:: [filter-app:pauser] - paste.filter_app_factory = deliverance.faketestingapps.Pauser + paste.filter_app_factory = deliverance.faketestingapps:Pauser # 10% of the time: probability = 10 # pause 5 seconds: Modified: z3/deliverance/trunk/deliverance/utils.py ============================================================================== --- z3/deliverance/trunk/deliverance/utils.py (original) +++ z3/deliverance/trunk/deliverance/utils.py Thu Jan 4 19:27:03 2007 @@ -246,7 +246,7 @@ - CSS_URL_PAT = re.compile(r'url\([\"\']*(.*?)[\"\']*\)',re.I) + CSS_URL_PAT = re.compile(r'url\(\s*[\"\']*(.*?)[\"\']*\s*\)',re.I) CSS_IMPORT_PAT = re.compile(r'\@import\s*[\"\'](.*?)[\"\']',re.I) def fixup_css_links(self, elts, base_uri): """ From ltucker at codespeak.net Thu Jan 4 20:12:31 2007 From: ltucker at codespeak.net (ltucker at codespeak.net) Date: Thu, 4 Jan 2007 20:12:31 +0100 (CET) Subject: [z3-checkins] r36156 - z3/deliverance/trunk/deliverance Message-ID: <20070104191231.A820D10070@code0.codespeak.net> Author: ltucker Date: Thu Jan 4 20:12:29 2007 New Revision: 36156 Modified: z3/deliverance/trunk/deliverance/interpreter.py Log: remove print Modified: z3/deliverance/trunk/deliverance/interpreter.py ============================================================================== --- z3/deliverance/trunk/deliverance/interpreter.py (original) +++ z3/deliverance/trunk/deliverance/interpreter.py Thu Jan 4 20:12:29 2007 @@ -428,6 +428,13 @@ theme_el.extend(content_els) + def get_content_els(rule, content): + xpath = self.get_content_xpath(rule) + if xpath: + return copy.deepcopy(content.xpath(self.get_content_xpath(rule))) + else: + return copy.deepcopy(rule.xpath("./*")) + def drop_els(self,doc,els): """ From ltucker at codespeak.net Thu Jan 4 20:14:47 2007 From: ltucker at codespeak.net (ltucker at codespeak.net) Date: Thu, 4 Jan 2007 20:14:47 +0100 (CET) Subject: [z3-checkins] r36157 - z3/deliverance/trunk/deliverance/test-data/aggregate Message-ID: <20070104191447.8C9DB10070@code0.codespeak.net> Author: ltucker Date: Thu Jan 4 20:14:45 2007 New Revision: 36157 Added: z3/deliverance/trunk/deliverance/test-data/aggregate/ z3/deliverance/trunk/deliverance/test-data/aggregate/example.html z3/deliverance/trunk/deliverance/test-data/aggregate/expected.html z3/deliverance/trunk/deliverance/test-data/aggregate/nav.html z3/deliverance/trunk/deliverance/test-data/aggregate/rules.xml z3/deliverance/trunk/deliverance/test-data/aggregate/theme.html Log: add missing test data for aggregate test Added: z3/deliverance/trunk/deliverance/test-data/aggregate/example.html ============================================================================== --- (empty file) +++ z3/deliverance/trunk/deliverance/test-data/aggregate/example.html Thu Jan 4 20:14:45 2007 @@ -0,0 +1,10 @@ + + + I am a title + + + Early text

Paragraph one

+

Paragraph two

+ extra + + Added: z3/deliverance/trunk/deliverance/test-data/aggregate/expected.html ============================================================================== --- (empty file) +++ z3/deliverance/trunk/deliverance/test-data/aggregate/expected.html Thu Jan 4 20:14:45 2007 @@ -0,0 +1,19 @@ + + + + I am a title + + + + + Some text +
+

Paragraph one

+

Paragraph two

+
+ external body text +

+
+
+ + Added: z3/deliverance/trunk/deliverance/test-data/aggregate/nav.html ============================================================================== --- (empty file) +++ z3/deliverance/trunk/deliverance/test-data/aggregate/nav.html Thu Jan 4 20:14:45 2007 @@ -0,0 +1,11 @@ + + + + +
+ + external body text +

+
+ + Added: z3/deliverance/trunk/deliverance/test-data/aggregate/rules.xml ============================================================================== --- (empty file) +++ z3/deliverance/trunk/deliverance/test-data/aggregate/rules.xml Thu Jan 4 20:14:45 2007 @@ -0,0 +1,13 @@ + + + + + + + + + + + + + Added: z3/deliverance/trunk/deliverance/test-data/aggregate/theme.html ============================================================================== --- (empty file) +++ z3/deliverance/trunk/deliverance/test-data/aggregate/theme.html Thu Jan 4 20:14:45 2007 @@ -0,0 +1,10 @@ + + + Example + + + + Some text +
replace this
+ + From kobold at codespeak.net Sun Jan 7 23:16:29 2007 From: kobold at codespeak.net (kobold at codespeak.net) Date: Sun, 7 Jan 2007 23:16:29 +0100 (CET) Subject: [z3-checkins] r36218 - in z3/sqlos/branch/kobold-sqlos/src/sqlos: . ftests Message-ID: <20070107221629.D607610070@code0.codespeak.net> Author: kobold Date: Sun Jan 7 23:16:28 2007 New Revision: 36218 Modified: z3/sqlos/branch/kobold-sqlos/src/sqlos/configure.zcml z3/sqlos/branch/kobold-sqlos/src/sqlos/ftests/localutilities.txt Log: Minor changes. Modified: z3/sqlos/branch/kobold-sqlos/src/sqlos/configure.zcml ============================================================================== --- z3/sqlos/branch/kobold-sqlos/src/sqlos/configure.zcml (original) +++ z3/sqlos/branch/kobold-sqlos/src/sqlos/configure.zcml Sun Jan 7 23:16:28 2007 @@ -156,7 +156,6 @@
- >> from zope.app import zapi + >>> import zope.component + >>> import zope.traversing.api >>> from zope.app.folder import Folder >>> from zope.app.component import interfaces as componentInterfaces >>> from zope.app.component.site import LocalSiteManager @@ -26,26 +27,19 @@ Let's get the connection name: >>> from sqlos.interfaces import IConnectionName - >>> connection_name = zapi.getUtility(IConnectionName).name + >>> connection_name = zope.component.getUtility(IConnectionName).name Now we set up a local database utility >>> from zope.rdb.interfaces import IZopeDatabaseAdapter - >>> from zope.app.component.interfaces.registration import ActiveStatus >>> from sqlos.testing.testdb import SQLiteda - >>> from zope.app.utility import UtilityRegistration >>> dbAdapter = SQLiteda(u'dbi://:memory:') - >>> reg = UtilityRegistration(connection_name, - ... IZopeDatabaseAdapter, - ... dbAdapter) - >>> default = sm['default'] - >>> key = default.registrationManager.addRegistration(reg) - >>> zapi.traverse(default.registrationManager, key).status = ActiveStatus + >>> sm.registerUtility(dbAdapter, provided=IZopeDatabaseAdapter, name=connection_name) >>> localUtility = sm.queryUtility(IZopeDatabaseAdapter, connection_name) - >>> localUtility - + >>> localUtility is dbAdapter + True >>> localUtility is dbAdapter True @@ -54,7 +48,7 @@ make sure that our localUtility is not identical to the global sqlite utility that has been registered through ftesting.zcml. - >>> gsm = zapi.getGlobalSiteManager() + >>> gsm = zope.component.getGlobalSiteManager() >>> globalUtility = gsm.queryUtility(IZopeDatabaseAdapter, connection_name) >>> globalUtility is not localUtility True @@ -67,7 +61,7 @@ ... '''create table dog ( ... id integer primary key, ... fullname varchar(50) not null, - ... owner_id integer not null)''') + ... owner varchar(20) not null)''') >>> c = cursor.execute( ... '''create table sample_isolated_person ( ... id integer primary key, From kobold at codespeak.net Sun Jan 7 23:16:42 2007 From: kobold at codespeak.net (kobold at codespeak.net) Date: Sun, 7 Jan 2007 23:16:42 +0100 (CET) Subject: [z3-checkins] r36219 - z3/sqlos/trunk/src/sqlos Message-ID: <20070107221642.619BE10078@code0.codespeak.net> Author: kobold Date: Sun Jan 7 23:16:41 2007 New Revision: 36219 Modified: z3/sqlos/trunk/src/sqlos/adapter.py z3/sqlos/trunk/src/sqlos/configure.zcml Log: Added support for psycopg2da. Modified: z3/sqlos/trunk/src/sqlos/adapter.py ============================================================================== --- z3/sqlos/trunk/src/sqlos/adapter.py (original) +++ z3/sqlos/trunk/src/sqlos/adapter.py Sun Jan 7 23:16:41 2007 @@ -148,6 +148,29 @@ self.supportTransactions = True +class Psycopg2Adapter(ConnectionAdapter, _postgres.builder()): + + def __init__(self, connection): + #The import is needed, as sqlobject uses self.module.Binary uppon + #startup. But until now we dont define .module. There is definitely + #need for a better solution. Propably the other adapters need this as + #well, but i cant test them, as i dont have them. + #Andres Freund - 2005-10-17 + if getattr(self, 'module', None) == None: + import psycopg2 + self.module = psycopg2 + #This is needed, because psycopg provides a optimized + #Binary() function which sqlobject dont get along with. This is + #normally done in sqlobject.postgres.pgconnection __init__ but we + #dont call that. + from sqlobject.postgres import pgconnection + registerConverter(type(psycopg2.Binary('')), + pgconnection.PsycoBinaryConverter) + + super(Psycopg2Adapter, self).__init__(connection) + self.supportTransactions = True + + class SQLiteAdapter(ConnectionAdapter, _sqlite.builder()): def __init__(self, connection): Modified: z3/sqlos/trunk/src/sqlos/configure.zcml ============================================================================== --- z3/sqlos/trunk/src/sqlos/configure.zcml (original) +++ z3/sqlos/trunk/src/sqlos/configure.zcml Sun Jan 7 23:16:41 2007 @@ -105,6 +105,15 @@ /> + + + + Author: kobold Date: Sun Jan 7 23:23:12 2007 New Revision: 36220 Added: z3/sqlos/trunk/src/sqlos/sqlos-configure.zcml z3/sqlos/trunk/src/sqlos/sqlos-ftesting.zcml z3/sqlos/trunk/src/sqlos/sqlos-meta.zcml Log: Added sqlos-*.zcml files for quick installation. Added: z3/sqlos/trunk/src/sqlos/sqlos-configure.zcml ============================================================================== --- (empty file) +++ z3/sqlos/trunk/src/sqlos/sqlos-configure.zcml Sun Jan 7 23:23:12 2007 @@ -0,0 +1 @@ + Added: z3/sqlos/trunk/src/sqlos/sqlos-ftesting.zcml ============================================================================== --- (empty file) +++ z3/sqlos/trunk/src/sqlos/sqlos-ftesting.zcml Sun Jan 7 23:23:12 2007 @@ -0,0 +1 @@ + Added: z3/sqlos/trunk/src/sqlos/sqlos-meta.zcml ============================================================================== --- (empty file) +++ z3/sqlos/trunk/src/sqlos/sqlos-meta.zcml Sun Jan 7 23:23:12 2007 @@ -0,0 +1 @@ + From kobold at codespeak.net Mon Jan 8 16:57:52 2007 From: kobold at codespeak.net (kobold at codespeak.net) Date: Mon, 8 Jan 2007 16:57:52 +0100 (CET) Subject: [z3-checkins] r36286 - in z3/sqlos/trunk/src/sqlos: . interfaces Message-ID: <20070108155752.BF8B91007A@code0.codespeak.net> Author: kobold Date: Mon Jan 8 16:57:48 2007 New Revision: 36286 Modified: z3/sqlos/trunk/src/sqlos/container.py z3/sqlos/trunk/src/sqlos/interfaces/__init__.py z3/sqlos/trunk/src/sqlos/zsqlobject.py Log: Backported minor fixes from the kobold-sqlos branch. Modified: z3/sqlos/trunk/src/sqlos/container.py ============================================================================== --- z3/sqlos/trunk/src/sqlos/container.py (original) +++ z3/sqlos/trunk/src/sqlos/container.py Mon Jan 8 16:57:48 2007 @@ -52,7 +52,7 @@ obj.__parent__ = parent if oldname != name and name is not None: - obj.__name__ = name + obj.__name__ = unicode(name) return obj @@ -100,7 +100,8 @@ """ Return a sequence-like object containing the names associated with the objects that appear in the folder """ - for name, obj in self.items(): yield name + for name, obj in self.items(): + yield name def __iter__(self): return iter(self.keys()) @@ -109,7 +110,8 @@ """ Return a sequence-like object containing the objects that appear in the folder. """ - for name, obj in self.items(): yield obj + for name, obj in self.items(): + yield contained(obj, parent=self, name=name) def items(self): """Return a sequence-like object containing tuples of the form @@ -153,7 +155,7 @@ if factoryName != utility_name: continue try: - obj = utility.get(id) + obj = utility.get(utility.sqlmeta.idType(id)) return contained(obj, parent=self, name=name) except (SQLObjectNotFound, ValueError): # SQlObject raises ValueError if the key is not correct @@ -167,7 +169,7 @@ KeyError is raised. """ try: - return self[name] + return contained(self[name], parent=self, name=name) except KeyError: return default @@ -252,5 +254,5 @@ obj = super(SQLIsolatedContainer, self).__getitem__(name) if hasattr(obj, 'domains'): if self.container_id in obj.domains: - return obj + return contained(obj, parent=self, name=name) raise KeyError, name Modified: z3/sqlos/trunk/src/sqlos/interfaces/__init__.py ============================================================================== --- z3/sqlos/trunk/src/sqlos/interfaces/__init__.py (original) +++ z3/sqlos/trunk/src/sqlos/interfaces/__init__.py Mon Jan 8 16:57:48 2007 @@ -16,6 +16,7 @@ from zope.schema.vocabulary import SimpleVocabulary from zope.schema import Choice, List from zope.annotation.interfaces import IAttributeAnnotatable +from zope.app.container.interfaces import IContained from sqlobject import NoDefault from sqlobject.dbconnection import DBConnection, DBAPI from sqlobject import _mysql, _postgres, _sybase @@ -267,7 +268,7 @@ similar to select() """ -class ISQLObject(Interface): +class ISQLObject(IContained): # XXX - _idName moved to sqlmeta #_idName = Attribute('Primary Key') Modified: z3/sqlos/trunk/src/sqlos/zsqlobject.py ============================================================================== --- z3/sqlos/trunk/src/sqlos/zsqlobject.py (original) +++ z3/sqlos/trunk/src/sqlos/zsqlobject.py Mon Jan 8 16:57:48 2007 @@ -13,6 +13,7 @@ from zope.interface import implements from sqlobject.main import SQLObject from sqlobject import StringCol +from zope.app.container.contained import Contained from sqlos.connection import ConnectionDescriptor from sqlos.interfaces import ISQLObject @@ -26,7 +27,7 @@ _transaction.dirty_object_registry.syncUpdateAll() -class SQLOS(SQLObject): +class SQLOS(SQLObject, Contained): """Subclass SQLObject to enable ``lazy updates`` by default, as well as adding knowledge to register ``dirty`` objects with SQLObjectTransactionManager so they get sync'd on transaction @@ -69,8 +70,11 @@ # objects in the cache that have a __parent__ set. # This may be confusing when expect to get a object # which has no __parent__ and thats not what you get. - val = super(SQLOS, self).get(id, connection=connection, - selectResults=selectResults) + try: + val = super(SQLOS, self).get(id, connection=connection, + selectResults=selectResults) + except ValueError: + raise AttributeError, id if getattr(val, '__parent__', None) is not None: val.__parent__ = None val.__name__ = None From kobold at codespeak.net Mon Jan 8 17:13:33 2007 From: kobold at codespeak.net (kobold at codespeak.net) Date: Mon, 8 Jan 2007 17:13:33 +0100 (CET) Subject: [z3-checkins] r36291 - in z3/sqlos/trunk: . includes Message-ID: <20070108161333.3A7D510070@code0.codespeak.net> Author: kobold Date: Mon Jan 8 17:13:31 2007 New Revision: 36291 Added: z3/sqlos/trunk/Makefile - copied unchanged from r36217, z3/sqlos/trunk/makefile Removed: z3/sqlos/trunk/TODO.txt z3/sqlos/trunk/includes/ z3/sqlos/trunk/makefile Modified: z3/sqlos/trunk/CONTRIBUTORS.txt z3/sqlos/trunk/COPYING.txt z3/sqlos/trunk/setup.py Log: Reorganized documentation; moved include files to src/sqlos. Modified: z3/sqlos/trunk/CONTRIBUTORS.txt ============================================================================== --- z3/sqlos/trunk/CONTRIBUTORS.txt (original) +++ z3/sqlos/trunk/CONTRIBUTORS.txt Mon Jan 8 17:13:31 2007 @@ -6,4 +6,5 @@ - Andrew Bennetts (spiv @ #launchpad) - Brian Sutherland (jinty at web.de) - Andres Freund (andres at anarazel.de) - - Adam Groszer + - Adam Groszer (adamg at fw.hu) + - Fabio Tranchitella (fabio@?ranchitella.it) Modified: z3/sqlos/trunk/COPYING.txt ============================================================================== --- z3/sqlos/trunk/COPYING.txt (original) +++ z3/sqlos/trunk/COPYING.txt Mon Jan 8 17:13:31 2007 @@ -3,3 +3,4 @@ Copyright (C) 2003-2004 sqlos, Enfold Systems LLC. Copyright (C) 2005-2006 sqlos, Brian Sutherland +Copyright (C) 2006-2007 sqlos, Fabio Tranchitella Deleted: /z3/sqlos/trunk/TODO.txt ============================================================================== --- /z3/sqlos/trunk/TODO.txt Mon Jan 8 17:13:31 2007 +++ (empty file) @@ -1,14 +0,0 @@ -TODO -==== - -Features --------- - -* Make it un-necessary to register the db adapter class in zcml. This is - required right now as there is no 'correct' way to tell which database a - IZopeConnection is for. - - - fixed for MySQL, should be fixed at least for postgres - -Bugs ----- Deleted: /z3/sqlos/trunk/makefile ============================================================================== --- /z3/sqlos/trunk/makefile Mon Jan 8 17:13:31 2007 +++ (empty file) @@ -1,67 +0,0 @@ -HERE=`pwd` -CSV=${HERE}/csv -ZP=${HERE}/../ -ZH=${HERE}/../../ -PYTHON=python2.4 -z3includes=Zope3/zopeskel/etc/package-includes -Z3BRANCH=trunk - -all : test clean - -doc : - export PYTHONPATH=${ZP} && epydoc -o docs/api --css blue --private-css green -v -n sqlos . - -sorted : - cat coverage_report | sort -k2 -r -n | grep 'sqlos' > coverage_sorted - -coverage : - cd ${ZH} && $(PYTHON) test.py -vpfT --all sqlos > ${HERE}/coverage_report - -coverage_sorted : coverage sorted - -.PHONY: clean -clean: - find . \( -name '*~' -o -name '*.py[co]' -o -name '*.bak' -o -name '#*#' -o -name '\.#*' \) -exec rm {} \; -print - $(PYTHON) setup.py clean - -.PHONY: realclean -realclean: clean - rm -rf dist - rm -rf build - rm -rf Zope3 - -.PHONY: z3-checkout -z3-checkout: - -test -d Zope3 || svn co svn://svn.zope.org/repos/main/Zope3/$(Z3BRANCH) Zope3 - -.PHONY: z3-update -z3-update: z3-checkout - svn up Zope3 - -Zope3: - $(MAKE) z3-checkout - -$(z3includes)/%.zcml: includes/%.zcml Zope3 - cp $< $@ - -.PHONY: sqlos-meta -sqlos-meta: $(z3includes)/sqlos-meta.zcml $(z3includes)/sqlos-configure.zcml $(z3includes)/sqlos-ftesting.zcml - -.PHONY: Zope3-build -Zope3-build: Zope3 - cd Zope3 && $(MAKE) PYTHON=$(PYTHON) inplace - -.PHONY: develop -develop: Zope3-build sqlos-meta - PYTHONPATH=Zope3/src $(PYTHON) setup.py develop --install-dir Zope3/src - -.PHONY: testall -test: develop - cd Zope3 && PYTHONPATH=src $(PYTHON) test.py --test-path=../src -s sqlos - -Zope3/principals.zcml: Zope3 Zope3/sample_principals.zcml - cp Zope3/sample_principals.zcml $@ - -.PHONY: run-sampleapp -run-sampleapp: develop Zope3/principals.zcml $(z3includes)/sqlos.ftesting-configure.zcml - cd Zope3; PYTHONPATH=src ./z3.py Modified: z3/sqlos/trunk/setup.py ============================================================================== --- z3/sqlos/trunk/setup.py (original) +++ z3/sqlos/trunk/setup.py Mon Jan 8 17:13:31 2007 @@ -20,5 +20,5 @@ include_package_data=True, install_requires = [ 'SQLObject>=0.7', - ] # XXX - what else? at least zope, let the users find out;) + ] ) From kobold at codespeak.net Mon Jan 8 17:14:58 2007 From: kobold at codespeak.net (kobold at codespeak.net) Date: Mon, 8 Jan 2007 17:14:58 +0100 (CET) Subject: [z3-checkins] r36292 - in z3/sqlos/trunk: . doc Message-ID: <20070108161458.33CC810078@code0.codespeak.net> Author: kobold Date: Mon Jan 8 17:14:57 2007 New Revision: 36292 Added: z3/sqlos/trunk/doc/CONTRIBUTORS.txt - copied unchanged from r36291, z3/sqlos/trunk/CONTRIBUTORS.txt z3/sqlos/trunk/doc/COPYING.txt - copied unchanged from r36291, z3/sqlos/trunk/COPYING.txt Removed: z3/sqlos/trunk/CONTRIBUTORS.txt z3/sqlos/trunk/COPYING.txt Log: Moved documentation files to the doc directory. Deleted: /z3/sqlos/trunk/CONTRIBUTORS.txt ============================================================================== --- /z3/sqlos/trunk/CONTRIBUTORS.txt Mon Jan 8 17:14:57 2007 +++ (empty file) @@ -1,10 +0,0 @@ -Contributors: - - - Sidnei da Silva (sidnei at awkly.org) - - Alan Runyan (runyaga at runyaga.com) - - Josh LaPlace (josh at clearnoodle.com) - - Andrew Bennetts (spiv @ #launchpad) - - Brian Sutherland (jinty at web.de) - - Andres Freund (andres at anarazel.de) - - Adam Groszer (adamg at fw.hu) - - Fabio Tranchitella (fabio@?ranchitella.it) Deleted: /z3/sqlos/trunk/COPYING.txt ============================================================================== --- /z3/sqlos/trunk/COPYING.txt Mon Jan 8 17:14:57 2007 +++ (empty file) @@ -1,6 +0,0 @@ -sqlos is distributed under the provisions of the Zope Public License -(ZPL) v2.1. See doc/ZopePublicLicense.txt for the license text. - -Copyright (C) 2003-2004 sqlos, Enfold Systems LLC. -Copyright (C) 2005-2006 sqlos, Brian Sutherland -Copyright (C) 2006-2007 sqlos, Fabio Tranchitella From kobold at codespeak.net Mon Jan 8 17:18:35 2007 From: kobold at codespeak.net (kobold at codespeak.net) Date: Mon, 8 Jan 2007 17:18:35 +0100 (CET) Subject: [z3-checkins] r36293 - z3/sqlos/trunk/doc Message-ID: <20070108161835.48DC310078@code0.codespeak.net> Author: kobold Date: Mon Jan 8 17:18:34 2007 New Revision: 36293 Modified: z3/sqlos/trunk/doc/CONTRIBUTORS.txt Log: Fixed my e-mail address. Modified: z3/sqlos/trunk/doc/CONTRIBUTORS.txt ============================================================================== --- z3/sqlos/trunk/doc/CONTRIBUTORS.txt (original) +++ z3/sqlos/trunk/doc/CONTRIBUTORS.txt Mon Jan 8 17:18:34 2007 @@ -7,4 +7,4 @@ - Brian Sutherland (jinty at web.de) - Andres Freund (andres at anarazel.de) - Adam Groszer (adamg at fw.hu) - - Fabio Tranchitella (fabio@?ranchitella.it) + - Fabio Tranchitella (fabio at tranchitella.it) From kobold at codespeak.net Mon Jan 8 17:58:43 2007 From: kobold at codespeak.net (kobold at codespeak.net) Date: Mon, 8 Jan 2007 17:58:43 +0100 (CET) Subject: [z3-checkins] r36298 - in z3/sqlos/trunk/src/sqlos: . tests Message-ID: <20070108165843.7C51910079@code0.codespeak.net> Author: kobold Date: Mon Jan 8 17:58:39 2007 New Revision: 36298 Modified: z3/sqlos/trunk/src/sqlos/__init__.py z3/sqlos/trunk/src/sqlos/configure.zcml z3/sqlos/trunk/src/sqlos/ftesting.zcml z3/sqlos/trunk/src/sqlos/meta.zcml z3/sqlos/trunk/src/sqlos/sampleapp.zcml z3/sqlos/trunk/src/sqlos/tests/__init__.py z3/sqlos/trunk/src/sqlos/tests/test_doctests.py z3/sqlos/trunk/src/sqlos/tests/test_transaction.py z3/sqlos/trunk/src/sqlos/tests/test_verify.py Log: Minor/cosmetic changes and deprecation warnings. Modified: z3/sqlos/trunk/src/sqlos/__init__.py ============================================================================== --- z3/sqlos/trunk/src/sqlos/__init__.py (original) +++ z3/sqlos/trunk/src/sqlos/__init__.py Mon Jan 8 17:58:39 2007 @@ -10,24 +10,7 @@ $Id$ """ -from datetime import datetime, date -from sqlobject.sqlbuilder import registerConverter +from zope.deprecation import deprecated -# sqlos.SQLOS is softly deprecated, will go away sometime -# (after at least one major release with deprecation warnings) -# import directly from sqlos.zsqlobject from sqlos.zsqlobject import SQLOS - - -## XXX: What are these?? I am sure there are no tests for them. - jinty -def DateTimeConverter(value, db=None): - return repr(value.isoformat()) - -registerConverter(datetime, DateTimeConverter) - -def DateConverter(value, db=None): - if isinstance(value, datetime): - return repr(value.date().isoformat()) - return repr(value.isoformat()) - -registerConverter(date, DateConverter) +deprecated('SQLOS', 'sqlos.SQLOS is deprecated and will go away in next release') Modified: z3/sqlos/trunk/src/sqlos/configure.zcml ============================================================================== --- z3/sqlos/trunk/src/sqlos/configure.zcml (original) +++ z3/sqlos/trunk/src/sqlos/configure.zcml Mon Jan 8 17:58:39 2007 @@ -1,3 +1,4 @@ + Modified: z3/sqlos/trunk/src/sqlos/sampleapp.zcml ============================================================================== --- z3/sqlos/trunk/src/sqlos/sampleapp.zcml (original) +++ z3/sqlos/trunk/src/sqlos/sampleapp.zcml Mon Jan 8 17:58:39 2007 @@ -1,3 +1,4 @@ + Modified: z3/sqlos/trunk/src/sqlos/tests/__init__.py ============================================================================== --- z3/sqlos/trunk/src/sqlos/tests/__init__.py (original) +++ z3/sqlos/trunk/src/sqlos/tests/__init__.py Mon Jan 8 17:58:39 2007 @@ -1 +0,0 @@ -# import this Modified: z3/sqlos/trunk/src/sqlos/tests/test_doctests.py ============================================================================== --- z3/sqlos/trunk/src/sqlos/tests/test_doctests.py (original) +++ z3/sqlos/trunk/src/sqlos/tests/test_doctests.py Mon Jan 8 17:58:39 2007 @@ -28,3 +28,6 @@ DocTestSuite('sqlos._transaction'), DocTestSuite('sqlos.zsqlobject') ]) + +if __name__=='__main__': + unittest.TextTestRunner().run(test_suite()) Modified: z3/sqlos/trunk/src/sqlos/tests/test_transaction.py ============================================================================== --- z3/sqlos/trunk/src/sqlos/tests/test_transaction.py (original) +++ z3/sqlos/trunk/src/sqlos/tests/test_transaction.py Mon Jan 8 17:58:39 2007 @@ -18,6 +18,7 @@ from zope.testing.doctestunit import DocTestSuite from transaction import get, begin + def doctest_KeepValuesOverExpireSync(): """Regression test for a SQLObject bug in expire. @@ -62,9 +63,10 @@ >>> tearDown() """ - def test_suite(): return unittest.TestSuite([ DocTestSuite(), ]) +if __name__=='__main__': + unittest.TextTestRunner().run(test_suite()) Modified: z3/sqlos/trunk/src/sqlos/tests/test_verify.py ============================================================================== --- z3/sqlos/trunk/src/sqlos/tests/test_verify.py (original) +++ z3/sqlos/trunk/src/sqlos/tests/test_verify.py Mon Jan 8 17:58:39 2007 @@ -16,17 +16,15 @@ $Id$ """ -from zope.interface import Interface, implements, classImplements +import unittest + from zope.interface.verify import verifyClass, verifyObject -from zope.interface.exceptions import DoesNotImplement, BrokenImplementation -from zope.interface.exceptions import BrokenMethodImplementation + from sqlobject.dbconnection import DBConnection, DBAPI from sqlobject import _mysql, _postgres, _sybase from sqlobject.main import SQLObject -from sqlos.interfaces import IDBConnection, \ - IDBAPI, ISQLConnection, ISQLObject +from sqlos.interfaces import IDBConnection, IDBAPI, ISQLConnection, ISQLObject -import unittest class Test(unittest.TestCase): @@ -34,7 +32,7 @@ self.failUnless(verifyClass(ISQLObject, SQLObject)) def testDBConnection(self): - self.failUnless(verifyClass(IDBConnection, DBConnection )) + self.failUnless(verifyClass(IDBConnection, DBConnection)) def testDBAPI(self): self.failUnless(verifyClass(IDBAPI, DBAPI)) From kobold at codespeak.net Mon Jan 8 18:08:01 2007 From: kobold at codespeak.net (kobold at codespeak.net) Date: Mon, 8 Jan 2007 18:08:01 +0100 (CET) Subject: [z3-checkins] r36300 - in z3/sqlos/trunk/src/sqlos: . container Message-ID: <20070108170801.D6B9810079@code0.codespeak.net> Author: kobold Date: Mon Jan 8 18:07:59 2007 New Revision: 36300 Added: z3/sqlos/trunk/src/sqlos/container/ z3/sqlos/trunk/src/sqlos/container/__init__.py - copied unchanged from r36286, z3/sqlos/trunk/src/sqlos/container.py Removed: z3/sqlos/trunk/src/sqlos/container.py Log: Transformed container.py module into a package. Deleted: /z3/sqlos/trunk/src/sqlos/container.py ============================================================================== --- /z3/sqlos/trunk/src/sqlos/container.py Mon Jan 8 18:07:59 2007 +++ (empty file) @@ -1,258 +0,0 @@ -############################################################################## -# -# Copyright (c) 2004 Enfold Systems LLC. All rights reserved. -# Copyright (c) 2005-2006 Brian Sutherland. All rights reserved. -# -# This software is distributed under the terms of the Zope Public -# License (ZPL) v2.1. See COPYING.txt for more information. -# -############################################################################## -""" -$Id$ -""" - -import random - -from sqlobject import * -from persistent import Persistent -from zope.interface import implements -from zope.component import IFactory -import zope.component -from zope.app.container.interfaces import IContained -from zope.app.container.contained import ContainedProxy -from zope.app.container.contained import Contained -from zope.app.container.contained import NameChooser -from zope.app.container.constraints import checkFactory -from zope.location.interfaces import ILocation -from zope.proxy import sameProxiedObjects -from zope.exceptions.interfaces import UserError - -from sqlos.interfaces import ISQLObject, ISQLObjectIsolated, IISQLObject -from sqlos.interfaces.container import ISQLObjectContainer -from sqlos.interfaces.container import IIsolatedSQLContainer - -def contained(obj, parent=None, name=None): - """An implementation of zope.app.container.contained.contained - that doesn't generate events, for internal use. - """ - if (parent is None): - raise TypeError, 'Must provide a parent' - - if not IContained.providedBy(obj): - if ILocation.providedBy(obj): - directlyProvides(obj, IContained, directlyProvidedBy(obj)) - else: - obj = ContainedProxy(obj) - - oldparent = obj.__parent__ - oldname = obj.__name__ - - if (oldparent is None) or not (oldparent is parent - or sameProxiedObjects(oldparent, parent)): - obj.__parent__ = parent - - if oldname != name and name is not None: - obj.__name__ = unicode(name) - - return obj - - -class SQLObjectNameChooser(NameChooser): - # XXX: This needs unit tests... - - def chooseName(self, name, obj): - if ISQLObject.providedBy(obj): - # Look for the SQLObject class our object is from, so get all - # allowed factories - for name, factory in zope.component.getFactoriesFor(ISQLObject): - if checkFactory(self.context, None, factory): - # get the sqlobject class - utility = zope.component.queryUtility(IISQLObject, name) - if utility is None: - continue - if obj.sqlmeta.table == utility.sqlmeta.table: - # if the tables names are the same, we assume that the - # sqlobject is an instance of that class, perhaps that - # is wrong - return "%s.%s" % (name, obj.id) - raise UserError("Cannot find a name") # XXX better message, i18n? - - -class SQLObjectContainer(Persistent, Contained): - - implements(ISQLObjectContainer) - - def __init__(self): - pass - - def _getAllowedIISQLObjectUtilities(self): - for name, factory in zope.component.getFactoriesFor(ISQLObject): - if checkFactory(self, None, factory): - utility = zope.component.queryUtility(IISQLObject, name) - # Someone might have registered a factory implementing - # IISQLObject using for whatever reason. - # in this case queryUtility returns None and we can just - # ignore it - if utility is not None: - yield name, utility - - def keys(self): - """ Return a sequence-like object containing the names - associated with the objects that appear in the folder - """ - for name, obj in self.items(): - yield name - - def __iter__(self): - return iter(self.keys()) - - def values(self): - """ Return a sequence-like object containing the objects that - appear in the folder. - """ - for name, obj in self.items(): - yield contained(obj, parent=self, name=name) - - def items(self): - """Return a sequence-like object containing tuples of the form - (name, object) for the objects that appear in the folder. - """ - for utility_name, utility in self._getAllowedIISQLObjectUtilities(): - for obj in utility.select(): - name = '%s.%s' % (utility_name, obj.id) - yield (name, contained(obj, parent=self, name=name)) - - def __getitem__(self, name): - """Return the named object. - - If the object is not found a KeyError is raised. - - lets get a container: - - >>> c = SQLObjectContainer() - - And make sure it doesn't bork on non-string values: - - >>> c[None] - Traceback (most recent call last): - ... - KeyError: ... - >>> c[object()] - Traceback (most recent call last): - ... - KeyError: ... - """ - if not isinstance(name, basestring): - raise KeyError, "%s is not a string" % name - try: - parts = name.split('.') - id = parts[-1] - factoryName = '.'.join(parts[:-1]) - except ValueError: - raise KeyError, name - - for utility_name, utility in self._getAllowedIISQLObjectUtilities(): - if factoryName != utility_name: - continue - try: - obj = utility.get(utility.sqlmeta.idType(id)) - return contained(obj, parent=self, name=name) - except (SQLObjectNotFound, ValueError): - # SQlObject raises ValueError if the key is not correct - raise KeyError, name - raise KeyError, name - - def get(self, name, default=None): - """Return the named object, or the value of the default - argument if given and the named object is not found. - If no default is given and the object is not found a - KeyError is raised. - """ - try: - return contained(self[name], parent=self, name=name) - except KeyError: - return default - - def __contains__(self, name): - """Return true if the named object appears in the folder.""" - return self.get(name, None) is not None - - def __len__(self): - """Return the number of objects in the folder.""" - i = 0 - for utility_name, utility in self._getAllowedIISQLObjectUtilities(): - i += utility.select().count() # optimal, does not get all objects - return i - - def __delitem__(self, name): - """Delete the named object from the container. - - Raises a KeyError if the object is not found. - """ - obj = self[name] - obj.destroySelf() - - def __setitem__(self, name, content): - return name - - -class SQLIsolatedContainer(SQLObjectContainer): - - implements(IIsolatedSQLContainer) - - _container_id = None - - def _getAllowedIISQLObjectUtilities(self): - # Ignore all utilities not implementing ISQLObjectIsolated - for name, utility in SQLObjectContainer._getAllowedIISQLObjectUtilities(self): - if ISQLObjectIsolated.implementedBy(utility): - yield name, utility - - def _getContainerId(self): - if self._container_id is None: - self._container_id = str(random.random()) # TODO better generation? - return self._container_id - def _setContainerId(self, value): - self._container_id = value - container_id = property(_getContainerId, _setContainerId) - - def __len__(self): - """Return the number of objects in the folder.""" - i = 0 - for name, utility in self._getAllowedIISQLObjectUtilities(): - i += utility.countByDomain(self.container_id) - return i - - def __delitem__(self, name): - """Delete the named object from the container. - - Raises a KeyError if the object is not found. - """ - obj = self[name] - domains = [d for d in obj.domains if d != self.container_id] - if not domains: - obj.destroySelf() - return - obj.domains = tuple(domains) - - def __setitem__(self, name, content): - domains = content.domains - if self.container_id not in domains: - content.domains = domains + (self.container_id, ) - return name - - def items(self): - """Return a sequence-like object containing tuples of the form - (name, object) for the objects that appear in the folder. - """ - for utility_name, utility in self._getAllowedIISQLObjectUtilities(): - for obj in utility.selectByDomain(self.container_id): - name = '%s.%s' % (utility_name, obj.id) - yield (name, contained(obj, parent=self, name=name)) - - def __getitem__(self, name): - obj = super(SQLIsolatedContainer, self).__getitem__(name) - if hasattr(obj, 'domains'): - if self.container_id in obj.domains: - return contained(obj, parent=self, name=name) - raise KeyError, name From kobold at codespeak.net Mon Jan 8 19:15:04 2007 From: kobold at codespeak.net (kobold at codespeak.net) Date: Mon, 8 Jan 2007 19:15:04 +0100 (CET) Subject: [z3-checkins] r36307 - in z3/sqlos/trunk/src/sqlos: container tests Message-ID: <20070108181504.197A410076@code0.codespeak.net> Author: kobold Date: Mon Jan 8 19:15:03 2007 New Revision: 36307 Added: z3/sqlos/trunk/src/sqlos/container/isolated.py - copied, changed from r36300, z3/sqlos/trunk/src/sqlos/container/__init__.py z3/sqlos/trunk/src/sqlos/container/standard.py Modified: z3/sqlos/trunk/src/sqlos/container/__init__.py z3/sqlos/trunk/src/sqlos/tests/test_doctests.py Log: Splitted containers in different files (actually, standard and isolated). Modified: z3/sqlos/trunk/src/sqlos/container/__init__.py ============================================================================== --- z3/sqlos/trunk/src/sqlos/container/__init__.py (original) +++ z3/sqlos/trunk/src/sqlos/container/__init__.py Mon Jan 8 19:15:03 2007 @@ -11,248 +11,5 @@ $Id$ """ -import random - -from sqlobject import * -from persistent import Persistent -from zope.interface import implements -from zope.component import IFactory -import zope.component -from zope.app.container.interfaces import IContained -from zope.app.container.contained import ContainedProxy -from zope.app.container.contained import Contained -from zope.app.container.contained import NameChooser -from zope.app.container.constraints import checkFactory -from zope.location.interfaces import ILocation -from zope.proxy import sameProxiedObjects -from zope.exceptions.interfaces import UserError - -from sqlos.interfaces import ISQLObject, ISQLObjectIsolated, IISQLObject -from sqlos.interfaces.container import ISQLObjectContainer -from sqlos.interfaces.container import IIsolatedSQLContainer - -def contained(obj, parent=None, name=None): - """An implementation of zope.app.container.contained.contained - that doesn't generate events, for internal use. - """ - if (parent is None): - raise TypeError, 'Must provide a parent' - - if not IContained.providedBy(obj): - if ILocation.providedBy(obj): - directlyProvides(obj, IContained, directlyProvidedBy(obj)) - else: - obj = ContainedProxy(obj) - - oldparent = obj.__parent__ - oldname = obj.__name__ - - if (oldparent is None) or not (oldparent is parent - or sameProxiedObjects(oldparent, parent)): - obj.__parent__ = parent - - if oldname != name and name is not None: - obj.__name__ = unicode(name) - - return obj - - -class SQLObjectNameChooser(NameChooser): - # XXX: This needs unit tests... - - def chooseName(self, name, obj): - if ISQLObject.providedBy(obj): - # Look for the SQLObject class our object is from, so get all - # allowed factories - for name, factory in zope.component.getFactoriesFor(ISQLObject): - if checkFactory(self.context, None, factory): - # get the sqlobject class - utility = zope.component.queryUtility(IISQLObject, name) - if utility is None: - continue - if obj.sqlmeta.table == utility.sqlmeta.table: - # if the tables names are the same, we assume that the - # sqlobject is an instance of that class, perhaps that - # is wrong - return "%s.%s" % (name, obj.id) - raise UserError("Cannot find a name") # XXX better message, i18n? - - -class SQLObjectContainer(Persistent, Contained): - - implements(ISQLObjectContainer) - - def __init__(self): - pass - - def _getAllowedIISQLObjectUtilities(self): - for name, factory in zope.component.getFactoriesFor(ISQLObject): - if checkFactory(self, None, factory): - utility = zope.component.queryUtility(IISQLObject, name) - # Someone might have registered a factory implementing - # IISQLObject using for whatever reason. - # in this case queryUtility returns None and we can just - # ignore it - if utility is not None: - yield name, utility - - def keys(self): - """ Return a sequence-like object containing the names - associated with the objects that appear in the folder - """ - for name, obj in self.items(): - yield name - - def __iter__(self): - return iter(self.keys()) - - def values(self): - """ Return a sequence-like object containing the objects that - appear in the folder. - """ - for name, obj in self.items(): - yield contained(obj, parent=self, name=name) - - def items(self): - """Return a sequence-like object containing tuples of the form - (name, object) for the objects that appear in the folder. - """ - for utility_name, utility in self._getAllowedIISQLObjectUtilities(): - for obj in utility.select(): - name = '%s.%s' % (utility_name, obj.id) - yield (name, contained(obj, parent=self, name=name)) - - def __getitem__(self, name): - """Return the named object. - - If the object is not found a KeyError is raised. - - lets get a container: - - >>> c = SQLObjectContainer() - - And make sure it doesn't bork on non-string values: - - >>> c[None] - Traceback (most recent call last): - ... - KeyError: ... - >>> c[object()] - Traceback (most recent call last): - ... - KeyError: ... - """ - if not isinstance(name, basestring): - raise KeyError, "%s is not a string" % name - try: - parts = name.split('.') - id = parts[-1] - factoryName = '.'.join(parts[:-1]) - except ValueError: - raise KeyError, name - - for utility_name, utility in self._getAllowedIISQLObjectUtilities(): - if factoryName != utility_name: - continue - try: - obj = utility.get(utility.sqlmeta.idType(id)) - return contained(obj, parent=self, name=name) - except (SQLObjectNotFound, ValueError): - # SQlObject raises ValueError if the key is not correct - raise KeyError, name - raise KeyError, name - - def get(self, name, default=None): - """Return the named object, or the value of the default - argument if given and the named object is not found. - If no default is given and the object is not found a - KeyError is raised. - """ - try: - return contained(self[name], parent=self, name=name) - except KeyError: - return default - - def __contains__(self, name): - """Return true if the named object appears in the folder.""" - return self.get(name, None) is not None - - def __len__(self): - """Return the number of objects in the folder.""" - i = 0 - for utility_name, utility in self._getAllowedIISQLObjectUtilities(): - i += utility.select().count() # optimal, does not get all objects - return i - - def __delitem__(self, name): - """Delete the named object from the container. - - Raises a KeyError if the object is not found. - """ - obj = self[name] - obj.destroySelf() - - def __setitem__(self, name, content): - return name - - -class SQLIsolatedContainer(SQLObjectContainer): - - implements(IIsolatedSQLContainer) - - _container_id = None - - def _getAllowedIISQLObjectUtilities(self): - # Ignore all utilities not implementing ISQLObjectIsolated - for name, utility in SQLObjectContainer._getAllowedIISQLObjectUtilities(self): - if ISQLObjectIsolated.implementedBy(utility): - yield name, utility - - def _getContainerId(self): - if self._container_id is None: - self._container_id = str(random.random()) # TODO better generation? - return self._container_id - def _setContainerId(self, value): - self._container_id = value - container_id = property(_getContainerId, _setContainerId) - - def __len__(self): - """Return the number of objects in the folder.""" - i = 0 - for name, utility in self._getAllowedIISQLObjectUtilities(): - i += utility.countByDomain(self.container_id) - return i - - def __delitem__(self, name): - """Delete the named object from the container. - - Raises a KeyError if the object is not found. - """ - obj = self[name] - domains = [d for d in obj.domains if d != self.container_id] - if not domains: - obj.destroySelf() - return - obj.domains = tuple(domains) - - def __setitem__(self, name, content): - domains = content.domains - if self.container_id not in domains: - content.domains = domains + (self.container_id, ) - return name - - def items(self): - """Return a sequence-like object containing tuples of the form - (name, object) for the objects that appear in the folder. - """ - for utility_name, utility in self._getAllowedIISQLObjectUtilities(): - for obj in utility.selectByDomain(self.container_id): - name = '%s.%s' % (utility_name, obj.id) - yield (name, contained(obj, parent=self, name=name)) - - def __getitem__(self, name): - obj = super(SQLIsolatedContainer, self).__getitem__(name) - if hasattr(obj, 'domains'): - if self.container_id in obj.domains: - return contained(obj, parent=self, name=name) - raise KeyError, name +from standard import contained, SQLObjectNameChooser, SQLObjectContainer +from isolated import SQLIsolatedContainer Copied: z3/sqlos/trunk/src/sqlos/container/isolated.py (from r36300, z3/sqlos/trunk/src/sqlos/container/__init__.py) ============================================================================== --- z3/sqlos/trunk/src/sqlos/container/__init__.py (original) +++ z3/sqlos/trunk/src/sqlos/container/isolated.py Mon Jan 8 19:15:03 2007 @@ -13,188 +13,12 @@ import random -from sqlobject import * -from persistent import Persistent from zope.interface import implements -from zope.component import IFactory -import zope.component -from zope.app.container.interfaces import IContained -from zope.app.container.contained import ContainedProxy -from zope.app.container.contained import Contained -from zope.app.container.contained import NameChooser -from zope.app.container.constraints import checkFactory -from zope.location.interfaces import ILocation -from zope.proxy import sameProxiedObjects -from zope.exceptions.interfaces import UserError -from sqlos.interfaces import ISQLObject, ISQLObjectIsolated, IISQLObject -from sqlos.interfaces.container import ISQLObjectContainer +from sqlos.container.standard import contained, SQLObjectContainer +from sqlos.interfaces import ISQLObjectIsolated from sqlos.interfaces.container import IIsolatedSQLContainer -def contained(obj, parent=None, name=None): - """An implementation of zope.app.container.contained.contained - that doesn't generate events, for internal use. - """ - if (parent is None): - raise TypeError, 'Must provide a parent' - - if not IContained.providedBy(obj): - if ILocation.providedBy(obj): - directlyProvides(obj, IContained, directlyProvidedBy(obj)) - else: - obj = ContainedProxy(obj) - - oldparent = obj.__parent__ - oldname = obj.__name__ - - if (oldparent is None) or not (oldparent is parent - or sameProxiedObjects(oldparent, parent)): - obj.__parent__ = parent - - if oldname != name and name is not None: - obj.__name__ = unicode(name) - - return obj - - -class SQLObjectNameChooser(NameChooser): - # XXX: This needs unit tests... - - def chooseName(self, name, obj): - if ISQLObject.providedBy(obj): - # Look for the SQLObject class our object is from, so get all - # allowed factories - for name, factory in zope.component.getFactoriesFor(ISQLObject): - if checkFactory(self.context, None, factory): - # get the sqlobject class - utility = zope.component.queryUtility(IISQLObject, name) - if utility is None: - continue - if obj.sqlmeta.table == utility.sqlmeta.table: - # if the tables names are the same, we assume that the - # sqlobject is an instance of that class, perhaps that - # is wrong - return "%s.%s" % (name, obj.id) - raise UserError("Cannot find a name") # XXX better message, i18n? - - -class SQLObjectContainer(Persistent, Contained): - - implements(ISQLObjectContainer) - - def __init__(self): - pass - - def _getAllowedIISQLObjectUtilities(self): - for name, factory in zope.component.getFactoriesFor(ISQLObject): - if checkFactory(self, None, factory): - utility = zope.component.queryUtility(IISQLObject, name) - # Someone might have registered a factory implementing - # IISQLObject using for whatever reason. - # in this case queryUtility returns None and we can just - # ignore it - if utility is not None: - yield name, utility - - def keys(self): - """ Return a sequence-like object containing the names - associated with the objects that appear in the folder - """ - for name, obj in self.items(): - yield name - - def __iter__(self): - return iter(self.keys()) - - def values(self): - """ Return a sequence-like object containing the objects that - appear in the folder. - """ - for name, obj in self.items(): - yield contained(obj, parent=self, name=name) - - def items(self): - """Return a sequence-like object containing tuples of the form - (name, object) for the objects that appear in the folder. - """ - for utility_name, utility in self._getAllowedIISQLObjectUtilities(): - for obj in utility.select(): - name = '%s.%s' % (utility_name, obj.id) - yield (name, contained(obj, parent=self, name=name)) - - def __getitem__(self, name): - """Return the named object. - - If the object is not found a KeyError is raised. - - lets get a container: - - >>> c = SQLObjectContainer() - - And make sure it doesn't bork on non-string values: - - >>> c[None] - Traceback (most recent call last): - ... - KeyError: ... - >>> c[object()] - Traceback (most recent call last): - ... - KeyError: ... - """ - if not isinstance(name, basestring): - raise KeyError, "%s is not a string" % name - try: - parts = name.split('.') - id = parts[-1] - factoryName = '.'.join(parts[:-1]) - except ValueError: - raise KeyError, name - - for utility_name, utility in self._getAllowedIISQLObjectUtilities(): - if factoryName != utility_name: - continue - try: - obj = utility.get(utility.sqlmeta.idType(id)) - return contained(obj, parent=self, name=name) - except (SQLObjectNotFound, ValueError): - # SQlObject raises ValueError if the key is not correct - raise KeyError, name - raise KeyError, name - - def get(self, name, default=None): - """Return the named object, or the value of the default - argument if given and the named object is not found. - If no default is given and the object is not found a - KeyError is raised. - """ - try: - return contained(self[name], parent=self, name=name) - except KeyError: - return default - - def __contains__(self, name): - """Return true if the named object appears in the folder.""" - return self.get(name, None) is not None - - def __len__(self): - """Return the number of objects in the folder.""" - i = 0 - for utility_name, utility in self._getAllowedIISQLObjectUtilities(): - i += utility.select().count() # optimal, does not get all objects - return i - - def __delitem__(self, name): - """Delete the named object from the container. - - Raises a KeyError if the object is not found. - """ - obj = self[name] - obj.destroySelf() - - def __setitem__(self, name, content): - return name - class SQLIsolatedContainer(SQLObjectContainer): Added: z3/sqlos/trunk/src/sqlos/container/standard.py ============================================================================== --- (empty file) +++ z3/sqlos/trunk/src/sqlos/container/standard.py Mon Jan 8 19:15:03 2007 @@ -0,0 +1,192 @@ +############################################################################## +# +# Copyright (c) 2004 Enfold Systems LLC. All rights reserved. +# Copyright (c) 2005-2006 Brian Sutherland. All rights reserved. +# +# This software is distributed under the terms of the Zope Public +# License (ZPL) v2.1. See COPYING.txt for more information. +# +############################################################################## +""" +$Id: __init__.py 36300 2007-01-08 17:07:59Z kobold $ +""" + +from persistent import Persistent +from sqlobject import SQLObjectNotFound + +from zope.interface import implements, directlyProvides, directlyProvidedBy +from zope.app.container.interfaces import IContained +from zope.app.container.constraints import checkFactory +from zope.app.container.contained import NameChooser, ContainedProxy, Contained +from zope.component import IFactory, getFactoriesFor, queryUtility +from zope.exceptions.interfaces import UserError +from zope.location.interfaces import ILocation +from zope.proxy import sameProxiedObjects + +from sqlos.interfaces import ISQLObject, IISQLObject +from sqlos.interfaces.container import ISQLObjectContainer + + +def contained(obj, parent=None, name=None): + """An implementation of zope.app.container.contained.contained + that doesn't generate events, for internal use. + """ + if (parent is None): + raise TypeError, 'Must provide a parent' + + if not IContained.providedBy(obj): + if ILocation.providedBy(obj): + directlyProvides(obj, IContained, directlyProvidedBy(obj)) + else: + obj = ContainedProxy(obj) + + oldparent = obj.__parent__ + oldname = obj.__name__ + + if (oldparent is None) or not (oldparent is parent + or sameProxiedObjects(oldparent, parent)): + obj.__parent__ = parent + + if oldname != name and name is not None: + obj.__name__ = unicode(name) + + return obj + + +class SQLObjectNameChooser(NameChooser): + """NameChooser for sqlos containers""" + + def chooseName(self, name, obj): + if ISQLObject.providedBy(obj): + # Look for the SQLObject class our object is from, so get all + # allowed factories + for name, factory in getFactoriesFor(ISQLObject): + if checkFactory(self.context, None, factory): + # get the sqlobject class + utility = queryUtility(IISQLObject, name) + if utility is None: + continue + if obj.sqlmeta.table == utility.sqlmeta.table: + # if the tables names are the same, we assume that the + # sqlobject is an instance of that class, perhaps that + # is wrong + return "%s.%s" % (name, obj.id) + raise UserError("Cannot find a name") # XXX better message, i18n? + + +class SQLObjectContainer(Persistent, Contained): + + implements(ISQLObjectContainer) + + def __init__(self): + pass + + def _getAllowedIISQLObjectUtilities(self): + for name, factory in getFactoriesFor(ISQLObject): + if checkFactory(self, None, factory): + utility = queryUtility(IISQLObject, name) + # Someone might have registered a factory implementing + # IISQLObject using for whatever reason. + # in this case queryUtility returns None and we can just + # ignore it + if utility is not None: + yield name, utility + + def keys(self): + """ Return a sequence-like object containing the names + associated with the objects that appear in the folder + """ + for name, obj in self.items(): + yield name + + def __iter__(self): + return iter(self.keys()) + + def values(self): + """ Return a sequence-like object containing the objects that + appear in the folder. + """ + for name, obj in self.items(): + yield contained(obj, parent=self, name=name) + + def items(self): + """Return a sequence-like object containing tuples of the form + (name, object) for the objects that appear in the folder. + """ + for utility_name, utility in self._getAllowedIISQLObjectUtilities(): + for obj in utility.select(): + name = '%s.%s' % (utility_name, obj.id) + yield (name, contained(obj, parent=self, name=name)) + + def __getitem__(self, name): + """Return the named object. + + If the object is not found a KeyError is raised. + + lets get a container: + + >>> c = SQLObjectContainer() + + And make sure it doesn't bork on non-string values: + + >>> c[None] + Traceback (most recent call last): + ... + KeyError: ... + >>> c[object()] + Traceback (most recent call last): + ... + KeyError: ... + """ + if not isinstance(name, basestring): + raise KeyError, "%s is not a string" % name + try: + parts = name.split('.') + id = parts[-1] + factoryName = '.'.join(parts[:-1]) + except ValueError: + raise KeyError, name + + for utility_name, utility in self._getAllowedIISQLObjectUtilities(): + if factoryName != utility_name: + continue + try: + obj = utility.get(utility.sqlmeta.idType(id)) + return contained(obj, parent=self, name=name) + except (SQLObjectNotFound, ValueError): + # SQlObject raises ValueError if the key is not correct + raise KeyError, name + raise KeyError, name + + def get(self, name, default=None): + """Return the named object, or the value of the default + argument if given and the named object is not found. + If no default is given and the object is not found a + KeyError is raised. + """ + try: + return contained(self[name], parent=self, name=name) + except KeyError: + return default + + def __contains__(self, name): + """Return true if the named object appears in the folder.""" + return self.get(name, None) is not None + + def __len__(self): + """Return the number of objects in the folder.""" + i = 0 + for utility_name, utility in self._getAllowedIISQLObjectUtilities(): + i += utility.select().count() # optimal, does not get all objects + return i + + def __delitem__(self, name): + """Delete the named object from the container. + + Raises a KeyError if the object is not found. + """ + obj = self[name] + obj.destroySelf() + + def __setitem__(self, name, content): + return name Modified: z3/sqlos/trunk/src/sqlos/tests/test_doctests.py ============================================================================== --- z3/sqlos/trunk/src/sqlos/tests/test_doctests.py (original) +++ z3/sqlos/trunk/src/sqlos/tests/test_doctests.py Mon Jan 8 19:15:03 2007 @@ -23,7 +23,8 @@ def test_suite(): return unittest.TestSuite([ - DocTestSuite('sqlos.container', optionflags=doctest.ELLIPSIS), + DocTestSuite('sqlos.container.standard', optionflags=doctest.ELLIPSIS), + DocTestSuite('sqlos.container.isolated', optionflags=doctest.ELLIPSIS), DocTestSuite('sqlos.connection'), DocTestSuite('sqlos._transaction'), DocTestSuite('sqlos.zsqlobject') From kobold at codespeak.net Mon Jan 8 20:13:18 2007 From: kobold at codespeak.net (kobold at codespeak.net) Date: Mon, 8 Jan 2007 20:13:18 +0100 (CET) Subject: [z3-checkins] r36313 - in z3/sqlos/trunk/src/sqlos: . container file file/tests ftests interfaces testing testing/tests tests Message-ID: <20070108191318.ED6CA10071@code0.codespeak.net> Author: kobold Date: Mon Jan 8 20:13:17 2007 New Revision: 36313 Added: z3/sqlos/trunk/src/sqlos/container/mono.py (contents, props changed) - copied, changed from r36307, z3/sqlos/trunk/src/sqlos/container/isolated.py z3/sqlos/trunk/src/sqlos/ftests/mono_containers.txt Modified: z3/sqlos/trunk/src/sqlos/__init__.py (props changed) z3/sqlos/trunk/src/sqlos/_transaction.py (props changed) z3/sqlos/trunk/src/sqlos/adapter.py (props changed) z3/sqlos/trunk/src/sqlos/configure.zcml z3/sqlos/trunk/src/sqlos/connection.py (props changed) z3/sqlos/trunk/src/sqlos/container/__init__.py (contents, props changed) z3/sqlos/trunk/src/sqlos/container/isolated.py (props changed) z3/sqlos/trunk/src/sqlos/container/standard.py (props changed) z3/sqlos/trunk/src/sqlos/file/__init__.py (props changed) z3/sqlos/trunk/src/sqlos/file/fsutility.py (props changed) z3/sqlos/trunk/src/sqlos/file/interfaces.py (props changed) z3/sqlos/trunk/src/sqlos/file/tests/__init__.py (props changed) z3/sqlos/trunk/src/sqlos/file/tests/test_fsutility.py (props changed) z3/sqlos/trunk/src/sqlos/ftests/__init__.py (props changed) z3/sqlos/trunk/src/sqlos/ftests/test_doctest.py (contents, props changed) z3/sqlos/trunk/src/sqlos/ftests/test_transaction.py (props changed) z3/sqlos/trunk/src/sqlos/interfaces/__init__.py (props changed) z3/sqlos/trunk/src/sqlos/interfaces/auth.py (props changed) z3/sqlos/trunk/src/sqlos/interfaces/container.py (contents, props changed) z3/sqlos/trunk/src/sqlos/metaconfigure.py (props changed) z3/sqlos/trunk/src/sqlos/metadirectives.py (props changed) z3/sqlos/trunk/src/sqlos/testing/__init__.py (props changed) z3/sqlos/trunk/src/sqlos/testing/sampleperson.py (contents, props changed) z3/sqlos/trunk/src/sqlos/testing/testdb.py (props changed) z3/sqlos/trunk/src/sqlos/testing/tests/__init__.py (props changed) z3/sqlos/trunk/src/sqlos/testing/tests/test_sampleperson.py (props changed) z3/sqlos/trunk/src/sqlos/tests/__init__.py (props changed) z3/sqlos/trunk/src/sqlos/tests/test_doctests.py (contents, props changed) z3/sqlos/trunk/src/sqlos/tests/test_transaction.py (props changed) z3/sqlos/trunk/src/sqlos/tests/test_verify.py (props changed) z3/sqlos/trunk/src/sqlos/zsqlobject.py (props changed) Log: Implemented mono containers; ftests for mono containers. Modified: z3/sqlos/trunk/src/sqlos/configure.zcml ============================================================================== --- z3/sqlos/trunk/src/sqlos/configure.zcml (original) +++ z3/sqlos/trunk/src/sqlos/configure.zcml Mon Jan 8 20:13:17 2007 @@ -39,6 +39,13 @@ factory=".container.SQLObjectNameChooser" /> + + >> c = SQLObjectMonoContainer() + >>> c.factory = "XXX" + + And make sure it doesn't bork on non-string values: + + >>> c[None] + Traceback (most recent call last): + ... + TypeError: Unable to look up ... + >>> c[object()] + Traceback (most recent call last): + ... + TypeError: Unable to look up ... + + """ + for utility_name, utility in self._getAllowedIISQLObjectUtilities(): + try: + obj = utility.get(utility.sqlmeta.idType(name)) return contained(obj, parent=self, name=name) + except (SQLObjectNotFound, ValueError): + raise KeyError, name raise KeyError, name Added: z3/sqlos/trunk/src/sqlos/ftests/mono_containers.txt ============================================================================== --- (empty file) +++ z3/sqlos/trunk/src/sqlos/ftests/mono_containers.txt Mon Jan 8 20:13:17 2007 @@ -0,0 +1,106 @@ +Functional test for SQLOSContainer objects +========================================== + +First, prepare the testing environment: + + >>> from sqlos.testing.sampleperson import SamplePerson, SamplePersonMonoContainer + >>> from sqlos.interfaces import ISQLObject + >>> from sqlos.interfaces.container import ISQLObjectMonoContainer + >>> from zope.interface.verify import verifyObject + >>> container = SamplePersonMonoContainer() + >>> verifyObject(ISQLObjectMonoContainer, container) + True + +We are not in the business of letting errors pass silently, so looking inside if +we get a database error (it must be of the type DatabaseException): + + >>> [i for i in container.items()] + Traceback (most recent call last): + ... + DatabaseException: ... + +So let's create some database tables if not already there: + + >>> from sqlos.testing.sampleperson import createTestingTables + >>> createTestingTables() + +We should now be able to look inside an empty container: + + >>> [i for i in container.keys()] + [] + >>> [i for i in container.items()] + [] + >>> [i for i in container] + [] + >>> [i for i in container.values()] + [] + >>> len(container) + 0 + +Lets create some objects: + + >>> people = [{'username': 'harry', + ... 'fullname': 'Harry the Hack', + ... 'password': 'harrypass'}, + ... {'username': 'sally', + ... 'fullname': 'Sally the Wack', + ... 'password': 'sallypass'}] + >>> from zope.app import zapi + >>> from sqlos.interfaces import IISQLObject + >>> SamplePerson = zapi.getUtility(IISQLObject, + ... u'sqlos.somename.SamplePerson', + ... context=container) + >>> harry = SamplePerson(**people[0]) + >>> len(container) + 1 + >>> sally = SamplePerson(**people[1]) + >>> len(container) + 2 + +Lets see whats inside: + + >>> [i[0] for i in container.items()] + [u'1', u'2'] + >>> [i[1] for i in container.items()] == [harry, sally] + True + >>> [i for i in container.values()] == [harry, sally] + True + >>> [i for i in container.keys()] + [u'1', u'2'] + >>> [i for i in container] + [u'1', u'2'] + +Let's test to see what the container does with bad id's (must raise KeyError): + + >>> container[3] + Traceback (most recent call last): + ... + KeyError: ... + +You can get() as well: + + >>> container.get(1) == harry + True + >>> container.get('sss', 'default') + 'default' + +Setitem passes but is really a no-op: + + >>> container['sss'] = 'yyy' + >>> len(container) + 2 + +Finally let's delete harry: + + >>> del container[1] + >>> len(container) + 1 + >>> container[1] + Traceback (most recent call last): + ... + KeyError: 1 + +CleanUp: + + >>> from sqlos.testing.sampleperson import dropTestingTables + >>> dropTestingTables() Modified: z3/sqlos/trunk/src/sqlos/ftests/test_doctest.py ============================================================================== --- z3/sqlos/trunk/src/sqlos/ftests/test_doctest.py (original) +++ z3/sqlos/trunk/src/sqlos/ftests/test_doctest.py Mon Jan 8 20:13:17 2007 @@ -24,5 +24,6 @@ 'connection.txt', 'containers.txt', 'localutilities.txt', - 'isolated_containers.txt'] + 'isolated_containers.txt', + 'mono_containers.txt'] return FunctionalDocFileSuite(*filelist) Modified: z3/sqlos/trunk/src/sqlos/interfaces/container.py ============================================================================== --- z3/sqlos/trunk/src/sqlos/interfaces/container.py (original) +++ z3/sqlos/trunk/src/sqlos/interfaces/container.py Mon Jan 8 20:13:17 2007 @@ -15,19 +15,26 @@ from zope.app.container.interfaces import IContainerNamesContainer from zope.app.container.interfaces import IReadContainer, IContainer + class ISQLObjectReadContainer(IReadContainer, IAttributeAnnotatable): - """ An SQLObject Container """ + """An SQLObject Container """ + class ISQLObjectContainer(IContainer, IContainerNamesContainer, IAttributeAnnotatable): - """ An SQLObject Container """ + """An SQLObject Container """ def __setitem__(name, obj): """Add a new object""" __setitem__.precondition = ItemTypePrecondition() + class IIsolatedSQLContainer(ISQLObjectContainer): # TODO Attribute -> zope.schema.* - jinty container_id = Attribute("The id of the containers, this is a filter on the" "database table.") + + +class ISQLObjectMonoContainer(ISQLObjectContainer): + """An SQLObject Container """ Modified: z3/sqlos/trunk/src/sqlos/testing/sampleperson.py ============================================================================== --- z3/sqlos/trunk/src/sqlos/testing/sampleperson.py (original) +++ z3/sqlos/trunk/src/sqlos/testing/sampleperson.py Mon Jan 8 20:13:17 2007 @@ -7,7 +7,7 @@ from sqlos.zsqlobject import SQLOS from sqlos.interfaces import ISQLSchema, IISQLObjectIsolated, ISQLObjectIsolated from sqlos.interfaces.container import ISQLObjectContainer -from sqlos.container import SQLObjectContainer, SQLIsolatedContainer +from sqlos.container import SQLObjectContainer, SQLIsolatedContainer, SQLObjectMonoContainer def createTestingTablesSubscriber(obj): # An event subscriber that can be used to create the testing tables @@ -55,6 +55,12 @@ implements(IPersonContainer) +class SamplePersonMonoContainer(SQLObjectMonoContainer): + + implements(IPersonContainer) + factory = 'sqlos.somename.SamplePerson' + + class SamplePerson(SQLOS): implements(IPerson, IPersonContained) Modified: z3/sqlos/trunk/src/sqlos/tests/test_doctests.py ============================================================================== --- z3/sqlos/trunk/src/sqlos/tests/test_doctests.py (original) +++ z3/sqlos/trunk/src/sqlos/tests/test_doctests.py Mon Jan 8 20:13:17 2007 @@ -25,6 +25,7 @@ return unittest.TestSuite([ DocTestSuite('sqlos.container.standard', optionflags=doctest.ELLIPSIS), DocTestSuite('sqlos.container.isolated', optionflags=doctest.ELLIPSIS), + DocTestSuite('sqlos.container.mono', optionflags=doctest.ELLIPSIS), DocTestSuite('sqlos.connection'), DocTestSuite('sqlos._transaction'), DocTestSuite('sqlos.zsqlobject') From ltucker at codespeak.net Mon Jan 8 20:19:08 2007 From: ltucker at codespeak.net (ltucker at codespeak.net) Date: Mon, 8 Jan 2007 20:19:08 +0100 (CET) Subject: [z3-checkins] r36314 - in z3/deliverance/trunk/deliverance: . test-data Message-ID: <20070108191908.36D4410071@code0.codespeak.net> Author: ltucker Date: Mon Jan 8 20:19:05 2007 New Revision: 36314 Added: z3/deliverance/trunk/deliverance/test-data/test_inline_javascript.xml Modified: z3/deliverance/trunk/deliverance/wsgimiddleware.py z3/deliverance/trunk/deliverance/xslt.py Log: fix inline javascript with braces in xslt, remove print statements Added: z3/deliverance/trunk/deliverance/test-data/test_inline_javascript.xml ============================================================================== --- (empty file) +++ z3/deliverance/trunk/deliverance/test-data/test_inline_javascript.xml Mon Jan 8 20:19:05 2007 @@ -0,0 +1,151 @@ + + + + + + + + + + + BlahDummy Content + + + + +
+ + + + + +
+ +

NEW: Daily email digests

+
+ + + + + + +
+ +
+ + + + + + + + + + + + +
+ + +
+ + + Blah + + + +
+ + + + + +
+ +

NEW: Daily email digests

+
+ + + + + + +
+ +
+ + + + + + + + + + + + +
+ +
+
+ + + + + + + + + BlahContent + + + + +
+ + + + + +
+ +

NEW: Daily email digests

+
+ + + + + + +
+ +
+ + + + + + + + + + + + +
+ + +
+ + + + + Content + + +
+ + + +
Modified: z3/deliverance/trunk/deliverance/wsgimiddleware.py ============================================================================== --- z3/deliverance/trunk/deliverance/wsgimiddleware.py (original) +++ z3/deliverance/trunk/deliverance/wsgimiddleware.py Mon Jan 8 20:19:05 2007 @@ -258,7 +258,6 @@ by using the wrapped WSGI application """ - print "get_internal_resource('%s')" % uri if 'paste.recursive.include' in in_environ: environ = in_environ['paste.recursive.include'].original_environ.copy() @@ -279,14 +278,12 @@ environ['QUERY_STRING'] = 'notheme' if 'HTTP_ACCEPT_ENCODING' in environ: - print "Knocking out ACCEPT_ENCODING: (%s)" % environ['HTTP_ACCEPT_ENCODING'] environ['HTTP_ACCEPT_ENCODING'] = '' if 'paste.recursive.include' in in_environ: # Try to do the redirect this way... includer = in_environ['paste.recursive.include'] res = includer(uri,environ) - print "did paste.recursive.include for %s: [%s]" % (uri,res.body) return res.body Modified: z3/deliverance/trunk/deliverance/xslt.py ============================================================================== --- z3/deliverance/trunk/deliverance/xslt.py (original) +++ z3/deliverance/trunk/deliverance/xslt.py Mon Jan 8 20:19:05 2007 @@ -72,6 +72,7 @@ self.fixup_links(theme_copy, theme_uri) self.xsl_escape_comments(theme_copy) + self.avt_escape(theme_copy) self.resolve_uri = reference_resolver if self.resolve_uri: @@ -466,5 +467,18 @@ del(rule.attrib[self.RULE_MOVE_KEY]) # just process it normally return + def avt_escape(self,elt): + """ + replaces all instances of { or } with {{ and }} to avoid + being interpreted as an Attribute Value Template by XSLT + """ + + for (k,v) in elt.attrib.items(): + escaped = v.replace('{','{{') + escaped = escaped.replace('}','}}') + elt.attrib[k] = escaped + + for child in elt: + self.avt_escape(child) From kobold at codespeak.net Mon Jan 8 20:48:55 2007 From: kobold at codespeak.net (kobold at codespeak.net) Date: Mon, 8 Jan 2007 20:48:55 +0100 (CET) Subject: [z3-checkins] r36315 - in z3/sqlos/trunk/src/sqlos: . container ftests interfaces testing Message-ID: <20070108194855.A8B0210071@code0.codespeak.net> Author: kobold Date: Mon Jan 8 20:48:54 2007 New Revision: 36315 Removed: z3/sqlos/trunk/src/sqlos/interfaces/auth.py Modified: z3/sqlos/trunk/src/sqlos/__init__.py z3/sqlos/trunk/src/sqlos/container/__init__.py z3/sqlos/trunk/src/sqlos/container/isolated.py z3/sqlos/trunk/src/sqlos/ftests/isolated_containers.txt z3/sqlos/trunk/src/sqlos/interfaces/__init__.py z3/sqlos/trunk/src/sqlos/interfaces/container.py z3/sqlos/trunk/src/sqlos/testing/sampleperson.py z3/sqlos/trunk/src/sqlos/zsqlobject.py Log: New API, with deprecation warnings for the old names: only isolated containeres are affected. Modified: z3/sqlos/trunk/src/sqlos/__init__.py ============================================================================== --- z3/sqlos/trunk/src/sqlos/__init__.py (original) +++ z3/sqlos/trunk/src/sqlos/__init__.py Mon Jan 8 20:48:54 2007 @@ -13,4 +13,5 @@ from zope.deprecation import deprecated from sqlos.zsqlobject import SQLOS -deprecated('SQLOS', 'sqlos.SQLOS is deprecated and will go away in next release') +deprecated('SQLOS', 'sqlos.SQLOS is deprecated and will go away in next release; ' +'use sqlos.zsqlobject.SQLOS instead.') Modified: z3/sqlos/trunk/src/sqlos/container/__init__.py ============================================================================== --- z3/sqlos/trunk/src/sqlos/container/__init__.py (original) +++ z3/sqlos/trunk/src/sqlos/container/__init__.py Mon Jan 8 20:48:54 2007 @@ -11,6 +11,13 @@ $Id$ """ +from zope.deprecation import deprecated + from standard import contained, SQLObjectNameChooser, SQLObjectContainer -from isolated import SQLIsolatedContainer +from isolated import SQLObjectIsolatedContainer from mono import SQLObjectMonoNameChooser, SQLObjectMonoContainer + +SQLIsolatedContainer = SQLObjectIsolatedContainer +deprecated('SQLIsolatedContainer', 'sqlos.container.SQLIsolatedContainer is deprecated ' +'and will go away in next release; use sqlos.container.SQLObjectIsolatedContainer ' +'instead.') Modified: z3/sqlos/trunk/src/sqlos/container/isolated.py ============================================================================== --- z3/sqlos/trunk/src/sqlos/container/isolated.py (original) +++ z3/sqlos/trunk/src/sqlos/container/isolated.py Mon Jan 8 20:48:54 2007 @@ -17,12 +17,12 @@ from sqlos.container.standard import contained, SQLObjectContainer from sqlos.interfaces import ISQLObjectIsolated -from sqlos.interfaces.container import IIsolatedSQLContainer +from sqlos.interfaces.container import ISQLObjectIsolatedContainer -class SQLIsolatedContainer(SQLObjectContainer): +class SQLObjectIsolatedContainer(SQLObjectContainer): - implements(IIsolatedSQLContainer) + implements(ISQLObjectIsolatedContainer) _container_id = None @@ -75,7 +75,7 @@ yield (name, contained(obj, parent=self, name=name)) def __getitem__(self, name): - obj = super(SQLIsolatedContainer, self).__getitem__(name) + obj = super(SQLObjectIsolatedContainer, self).__getitem__(name) if hasattr(obj, 'domains'): if self.container_id in obj.domains: return contained(obj, parent=self, name=name) Modified: z3/sqlos/trunk/src/sqlos/ftests/isolated_containers.txt ============================================================================== --- z3/sqlos/trunk/src/sqlos/ftests/isolated_containers.txt (original) +++ z3/sqlos/trunk/src/sqlos/ftests/isolated_containers.txt Mon Jan 8 20:48:54 2007 @@ -1,11 +1,11 @@ First let's get a container for sqlos objects: >>> from sqlos.testing import sampleperson - >>> from sqlos.interfaces.container import IIsolatedSQLContainer + >>> from sqlos.interfaces.container import ISQLObjectIsolatedContainer >>> from zope.interface.verify import verifyObject >>> container = sampleperson.SampleIsolatedPersonContainer() - >>> verifyObject(IIsolatedSQLContainer, container) + >>> verifyObject(ISQLObjectIsolatedContainer, container) True We are not in the business of letting errors pass silently, so looking inside Modified: z3/sqlos/trunk/src/sqlos/interfaces/__init__.py ============================================================================== --- z3/sqlos/trunk/src/sqlos/interfaces/__init__.py (original) +++ z3/sqlos/trunk/src/sqlos/interfaces/__init__.py Mon Jan 8 20:48:54 2007 @@ -23,235 +23,208 @@ from sqlobject.main import SQLObject, SelectResults from sqlobject.sqlbuilder import SQLObjectTable + class IConnectionName(Interface): """A marker interface for providing a connection name""" name = TextLine( title=u"Connection Name", - required=True + required=True, ) + class ISQLSchema(Interface): - """ SQLObject-based schemas must declare 'id' or else it doesn't - get security set """ + """Base interface for SQLObject-based objects""" id = Attribute('Id') + class IDBConnection(Interface): - """ SQLObject DBConnection interface """ + """SQLObject DBConnection interface""" - name = Attribute("The object name, used as key for caching connections") + name = Attribute("The object name, used as key for caching connections") debug = Attribute("Print debug trace messages") cache = Attribute("A ResultSet cache object") style = Attribute("A style object. Used for controlling the naming style.") + class IDBAPI(IDBConnection): + """DBAPI Interface""" def _runWithConnection(meth, *args): - """ Runs a method with a connection from the pool """ + """Runs a method with a connection from the pool""" def getConnection(): - """ Return a connection from the pool """ + """Return a connection from the pool""" def releaseConnection(conn): - """ Return a connection back to the pool """ + """Return a connection back to the pool""" def query(s): - """ Run a query string against the database """ + """Run a query string against the database""" def queryAll(s): - """ Run a query string against the database and return all results """ + """Run a query string against the database and return all results""" def queryOne(s): - """ Run a query string against the database and return one row """ + """Run a query string against the database and return one row""" def transaction(): - """ Return a transaction object for this connection """ + """Return a transaction object for this connection""" def queryInsertID(soInstance, id, names, values): - """ Insert a row into the database and return the generated id """ + """Insert a row into the database and return the generated id""" def iterSelect(select): - """ """ + """Iter on a select""" def queryForSelect(select): - """ """ + """Query for a select""" def createTable(soClass): - """ Create a table for the given SQLObject class """ + """Create a table for the given SQLObject class""" def createColumns(soClass): - """ Return a query needed to create the columns for the given SO class """ + """Return a query needed to create the columns for the given SO class""" def dropTable(tableName): - """ Drop the given table """ + """Drop the given table""" def clearTable(tableName): - """ Clear the given table """ - - ### Private methods + """Clear the given table""" def _SO_update(so, values): - """ """ + """""" def _SO_selectOne(so, columnNames): - """ """ + """""" def _SO_selectOneAlt(cls, columnNames, column, value): - """ """ + """""" def _SO_delete(so): - """ """ + """""" def _SO_selectJoin(soClass, column, value): - """ """ + """""" def _SO_intermediateJoin(table, getColumn, joinColumn, value): - """ """ + """""" def _SO_intermediateDelete(table, firstColumn, firstValue, secondColumn, secondValue): - """ """ + """""" def _SO_intermediateInsert(table, firstColumn, firstValue, secondColumn, secondValue): - """ """ + """""" def _SO_columnClause(soClass, kw): - """ """ + """""" + class ISQLConnection(IDBAPI): def makeConnection(): - """ Return a newly-built connection instance using args passed - on __init__ """ + """Return a newly-built connection instance""" def getConnection(): - """ Get a connection from the pool """ + """Get a connection from the pool""" def _runWithConnection(meth, *args): - """ Run a method with the give args and a connection """ + """Run a method with the give args and a connection""" def createColumn(soClass, column): - """ Create a column """ + """Create a column""" def createIDColumn(soClass): - """ Return the string used to create the ID column """ + """Return the string used to create the ID column""" def joinSQLType(join): - """ Return the string to be used in join queries """ + """Return the string to be used in join queries""" def tableExists(tableName): - """ Return if the given table exists or not in the database """ + """Return if the given table exists or not in the database""" def addColumn(tableName, column): - """ Add the given column to the database """ + """Add the given column to the database""" def delColumn(tableName, column): - """ Remove the given column from the database """ + """Remove the given column from the database""" def columnsFromSchema(tableName, soClass): - """ Return a set of columns from the table schema """ + """Return a set of columns from the table schema""" def guessClass(t): - """ Returns a column class and a dict to be used on column - initialization """ + """Returns a column class and a dict to be used on column initialization""" + class IZopeSQLConnection(ISQLConnection): - """ """ + """Marker for Zope relational database connections""" -class ISQLAttributeAnnotatable(IAttributeAnnotatable): - """ - Store annotations in the annotations table, keyed by - table_name/id on a IAttributeAnnotatable object. - """ class IReadSQLObjectClass(Interface): - q = Attribute('Query?') + q = Attribute('Query') def get(id): - """Return object by the given primary key. - """ + """Return object by the given primary key.""" def sqlrepr(value): - """ Shorthand for _connection.sqlrepr - """ + """Shorthand for _connection.sqlrepr""" def select(clause=None, clauseTables=None, orderBy=NoDefault, groupBy=None, limit=None, lazyColumns=False, reversed=False): - """ Do a select query and return the resulting objects. - """ + """Do a select query and return the resulting objects.""" def selectBy(**kw): - """ """ + """Do a select query filtering by the specified keywords""" + class IWriteSQLObjectClass(Interface): def delete(id): - """ Delete item by primary key id. - """ - - # XXX these moved to sqlmeta in sqlobject 0.7, should we define another - # interface? - #def addColumn(columnDef, changeSchema=False): - # """ Add a column to the class. If changeSchema is True, also - # add the column to the database. Also generates getter and - # setter methods on the class. - # """ - # - #def addColumnsFromDatabase(): - # """ Add to the class the columns that are defined on the - # database but not already present. - # """ - # - #def delColumn(column, changeSchema=False): - # """ Delete the given column from the class. 'column' may be - # either a string or a Col instance. If changeSchema is true, - # also remove the column from the database table. - # """ - # - #def addJoin(joinDef): - # """ Add a join definition to the class, optionally removing or - # adding items as requested. - # """ - # - #def delJoin(joinDef): - # """ Remove a join definition from the class, optionally - # removing or adding items as requested. - # """ + """Delete item by primary key id.""" def dropTable(ifExists=False, dropJoinTables=True): - """ Drop the table. If the 'ifExists' parameter was passed, - check if the table exists before trying to delete. If - 'dropJoinTables' is True, drop the join tables associated. + """Drop the table. + + If the 'ifExists' parameter was passed, check if the table exists + before trying to delete. If 'dropJoinTables' is True, drop the join + tables associated. """ def createTable(ifNotExists=False, createJoinTables=True): - """ Create the table. If the 'ifNotExists' parameter was - passed, check if the table exists before trying to create. If - 'createJoinTables' is True, create the join tables associated. + """Create the table. + + If the 'ifNotExists' parameter was passed, check if the table exists + before trying to create. If 'createJoinTables' is True, create the join + tables associated. """ + def createJoinTables(ifNotExists=False): - """ Create the associated join tables. If the 'ifNotExists' - parameter is True, check if the tables doesn't already exist - first. + """Create the associated join tables. + + If the 'ifNotExists' parameter is True, check if the tables doesn't + already exist first. """ def dropJoinTables(ifExists=False): - """ Drop the associated join tables. If the 'ifExists' - parameter is True, then first check if the tables exist before - trying to delete. + """Drop the associated join tables. + + If the 'ifExists' parameter is True, then first check if the tables + exist before trying to delete. """ def clearTable(): - """ Clear the table. - """ + """Clear the table.""" + class IISQLObject(IReadSQLObjectClass, IWriteSQLObjectClass): """Class methods for SQLObject classes.""" + class IISQLObjectIsolated(IISQLObject): """Support for using this class in isolated containers. @@ -268,34 +241,30 @@ similar to select() """ -class ISQLObject(IContained): - - # XXX - _idName moved to sqlmeta - #_idName = Attribute('Primary Key') +class ISQLObject(IContained): def set(**kw): - """ Used to update multiple values at once, potentially with - one SQL statement if possible. + """Used to update multiple values at once, potentially with one SQL + statement if possible. """ def destroySelf(): - """ Kill this object and remove it f