Author: jmorliaguet Date: Sun May 21 11:46:07 2006 New Revision: 3178 Added: cpsskins/branches/paris-sprint-2006/setup/io/README.txt (contents, props changed) Modified: cpsskins/branches/paris-sprint-2006/ftests/test_appsetup.py cpsskins/branches/paris-sprint-2006/setup/README.txt cpsskins/branches/paris-sprint-2006/setup/manager.py
Log: - moved IO tests to setup/IO Modified: cpsskins/branches/paris-sprint-2006/ftests/test_appsetup.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/ftests/test_appsetup.py (original) +++ cpsskins/branches/paris-sprint-2006/ftests/test_appsetup.py Sun May 21 11:46:07 2006 @@ -52,6 +52,7 @@ def test_suite(): return unittest.TestSuite(( FunctionalDocFileSuite('../setup/README.txt', setUp=setUp), + FunctionalDocFileSuite('../setup/io/README.txt', setUp=setUp), )) if __name__ == '__main__': Modified: cpsskins/branches/paris-sprint-2006/setup/README.txt ============================================================================== --- cpsskins/branches/paris-sprint-2006/setup/README.txt (original) +++ cpsskins/branches/paris-sprint-2006/setup/README.txt Sun May 21 11:46:07 2006 @@ -128,7 +128,7 @@ >>> resources.unregister(uri=u'cpsskins://[EMAIL PROTECTED]', context=root) Traceback (most recent call last): ... - ValueError: No such local setting: 'cpsskins://[EMAIL PROTECTED]' + ValueError: No such setting: 'cpsskins://[EMAIL PROTECTED]' so we register a local resource, we do this by passing a context to register(): @@ -157,21 +157,14 @@ Unregistering settings ---------------------- -when unregistering a setting, a context must be given: - - >>> resources.unregister(uri=u'cpsskins://[EMAIL PROTECTED]') - Traceback (most recent call last): - ... - ValueError: Must specify a context. - -and a setting URI must be specified: +when unregistering a setting, a setting URI must be specified: >>> resources.unregister(context=root) Traceback (most recent call last): ... KeyError: 'Must specify a setting URI.' -so we pass both: +if a context is specified, the resource is unregistered locally: >>> resources.unregister(uri='cpsskins://[EMAIL PROTECTED]', context=root) @@ -492,302 +485,7 @@ Export of resources =================== -Resources can be exported using the IDOMAdapter adapter. - - >>> from zope.component import getMultiAdapter - - >>> from xml.dom.minidom import DOMImplementation - >>> dom = DOMImplementation() - - >>> from cpsskins.setup.io.interfaces import IDOMAdapter - - >>> def toXML(obj, title=u'resources', attributes=(), ignored=(), - ... archive=None): - ... document = dom.createDocument(None, title, None) - ... doc = document.documentElement - ... exporter = getMultiAdapter((obj, doc), IDOMAdapter) - ... exporter.archive = archive - ... exporter.document = document - ... exporter.fields_as_attributes = attributes - ... exporter.ignored_fields = ignored - ... exporter.save() - ... return document.toprettyxml(indent=u' ', encoding=u'utf-8') - - -Export of styles ----------------- - - >>> resource = Style() - >>> resource[u'div.body'] = {'color': u'red', 'border': u'none'} - - >>> print toXML(resource, u'styles') - <?xml version="1.0" encoding="utf-8"?> - <styles> - <style id="..."> - <rule selector="div.body"> - <property name="color" value="red"/> - <property name="border" value="none"/> - </rule> - </style> - </styles> - <BLANKLINE> - -Export of settings ------------------- - - >>> style = Style() - >>> style[u'h1'] = {'color': 'red'} - >>> root[u'style-1'] = style - >>> resources.register(name=u'style1', title=u'Style 1', resource=style) - <Setting: cpsskins://[EMAIL PROTECTED]> - -When exporting settings, the resource's own type is skipped, we write: - - <setting ... type="format-style"> - <rule> - ... - </rule> - </setting> - -instead of: - - <setting ... type="format-style"> - <style id="..."> - <rule> - ... - </rule> - </style> - </setting> - - >>> setting = resources.lookup(u'cpsskins://[EMAIL PROTECTED]') - >>> print toXML(setting, u'settings') - <?xml version="1.0" encoding="utf-8"?> - <settings> - <setting custom="False" name="style1" title="Style 1" type="format-style"> - <rule selector="h1"> - <property name="color" value="red"/> - </rule> - </setting> - </settings> - <BLANKLINE> - -Export of relations -------------------- - -Monadic relations: - - >>> from cpsskins.relations import MonadicRelation, Predicate - - >>> relation = MonadicRelation(predicate=Predicate(u'_ A'), - ... first=Actions(u'Actions portlet')) - - >>> print toXML(relation, u'relations') - <?xml version="1.0" encoding="utf-8"?> - <relations> - <monad predicate="_ A"> - <relate uri="cpsskins://canvas-portlet-standard.actions:..."/> - </monad> - </relations> - <BLANKLINE> - - -Dyadic relations: - - >>> from cpsskins.standard.portlets.breadcrumbs.portlet import Breadcrumbs - >>> from cpsskins.relations import DyadicRelation - - >>> relation = DyadicRelation(predicate=Predicate(u'_ B _'), - ... first=Actions(u'Actions portlet'), - ... second=Breadcrumbs(u'Breadcrumbs portlet')) - - >>> print toXML(relation, u'relations') - <?xml version="1.0" encoding="utf-8"?> - <relations> - <dyad predicate="_ B _"> - <relate uri="cpsskins://canvas-portlet-standard.actions:..."/> - <relate uri="cpsskins://canvas-portlet-standard.breadcrumbs:..."/> - </dyad> - </relations> - <BLANKLINE> - - -Triadic relations: - - >>> from cpsskins.relations import TriadicRelation - >>> from cpsskins.elements.slot import Slot - - >>> relation = TriadicRelation(predicate=Predicate(u'_ C _ D _'), - ... first=Actions(u'Actions portlet'), - ... second=Breadcrumbs(u'Breadcrumbs portlet'), - ... third=Slot(slot=u'slotA')) - - >>> print toXML(relation, u'relations') - <?xml version="1.0" encoding="utf-8"?> - <relations> - <triad predicate="_ C _ D _"> - <relate uri="cpsskins://canvas-portlet-standard.actions:..."/> - <relate uri="cpsskins://canvas-portlet-standard.breadcrumbs:..."/> - <relate uri="cpsskins://canvas-slot:slotA"/> - </triad> - </relations> - <BLANKLINE> - - -Export of elements ------------------- - - >>> from cpsskins.elements.pageblock import PageBlock - >>> pageblock = PageBlock(u'Some page block') - - >>> root['pageblock'] = pageblock - - >>> from cpsskins.elements.cell import Cell - >>> cell1 = Cell(u'Some cell 1') - >>> cell2 = Cell(u'Some cell 2') - - >>> pageblock[u'cell1'] = cell1 - >>> pageblock[u'cell2'] = cell2 - - >>> from cpsskins.elements.slot import Slot - >>> slot = Slot(u'Some slot', slot=u'slot1') - >>> pageblock[u'cell1'][u'slot'] = slot - - >>> print toXML(pageblock, u'elements', (u'title', u'description'), - ... (u'slot',)) - <?xml version="1.0" encoding="utf-8"?> - <elements> - <pageblock id="..." title="Some page block"> - <cell id="..." title="Some cell 1"> - <slot description="" id="slot1" title="Some slot"/> - </cell> - <cell id="..." title="Some cell 2"/> - </pageblock> - </elements> - <BLANKLINE> - - -Export of container elements ----------------------------- - - >>> from cpsskins.tests.setup import addThemeManager, addThemeSkeleton - >>> root = getRootFolder() - >>> theme = addThemeSkeleton(tmutil) - - >>> print toXML(theme, u'themes', (u'title', ), (u'slot',)) - <?xml version="1.0" encoding="utf-8"?> - <themes> - <theme id="..." title="A theme"> - <themepage id="..." title="A page"> - <pageblock id="..." title="A page block"> - <cell id="..." title="A cell"/> - </pageblock> - </themepage> - </theme> - </themes> - <BLANKLINE> - -Export of portlets ------------------- - - >>> portlet = Actions(title=u'Action portlet', category=u'zmi_views') - - >>> print toXML(portlet, u'portlets', (u'title', )) - <?xml version="1.0" encoding="utf-8"?> - <portlets> - <portlet id="..." title="Action portlet" type="standard.actions"> - <category value="zmi_views"/> - </portlet> - </portlets> - <BLANKLINE> - -Export of display elements -------------------------- - - >>> from cpsskins.standard.displays.area import Area - >>> area = Area() - - >>> print toXML(area, u'displays') - <?xml version="1.0" encoding="utf-8"?> - <displays> - <area id="..."/> - </displays> - <BLANKLINE> - -Export of format elements -------------------------- - - >>> from cpsskins.standard.formats.effect import Effect - >>> effect = Effect(width=100, height=80) - - >>> print toXML(effect, u'formats') - <?xml version="1.0" encoding="utf-8"?> - <formats> - <effect id="..."> - <types value=""/> - <format value="PNG"/> - <width value="100"/> - <height value="80"/> - <keep_ratio value="True"/> - </effect> - </formats> - <BLANKLINE> - -Export of binary data ---------------------- - - >>> from cpsskins.standard.portlets.image.portlet import Image - >>> portlet = Image(title=u'Image portlet') - >>> portlet.contentType = u'image/png' - - >>> portlet.data = "\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00x" \ - ... "\x00\x00\x00x\x01\x03\x00\x00\x00\x03\xaa\xa4\x91\x00\x00\x00" \ - ... "\x03PLTE\xff\xff\xff\xa7\xc4\x1b\xc8\x00\x00\x00\x17IDAT8\xcbc`" \ - ... "\x18\x05\xa3`\x14\x8c\x82Q0\nF\x01\xbd\x01\x00\x07\x80\x00\x01:" \ - ... "\xe7\xca\xd4\x00\x00\x00\x00IEND\xaeB`\x82" - - >>> root[u'portlet-1'] = portlet - - >>> from zope.app.file.image import getImageInfo - >>> getImageInfo(portlet.data) - ('image/png', 120, 120) - - >>> archive = {} - - >>> print toXML(portlet, u'portlets', archive=archive) - <?xml version="1.0" encoding="utf-8"?> - <portlets> - <portlet id="..." type="standard.image"> - <title value="Image portlet"/> - <link value=""/> - <data value="..._data_120x120.png"/> - <contentType value="image/png"/> - </portlet> - </portlets> - <BLANKLINE> - - >>> binary_name = u'%s_data_120x120.png' % portlet.identifier - >>> archive[binary_name] == portlet.data - True - -Export of fields ----------------- - - >>> from cpsskins.standard.fields.color import Color - >>> blue = Color(r=0, g=0, b=255) - >>> root[u'color-1'] = blue - >>> print blue - #0000ff - - >>> archive = {} - >>> print toXML(blue, u'colors', archive=archive) - <?xml version="1.0" encoding="utf-8"?> - <colors> - <color id="..."> - <rgb value="0, 0, 255"/> - </color> - </colors> - <BLANKLINE> - +See io/README.txt Resolving URIs ============== @@ -797,7 +495,8 @@ Resources can be accessed by using the name of the setting under which the resource has been registered (cpsskins://[EMAIL PROTECTED]). - >>> color = Color(r=255, g=0, b=0) + >>> from cpsskins.standard.fields.color import WebColor + >>> color = WebColor(r=255, g=0, b=0) >>> root[u'color'] = color >>> print color #ff0000 Added: cpsskins/branches/paris-sprint-2006/setup/io/README.txt ============================================================================== --- (empty file) +++ cpsskins/branches/paris-sprint-2006/setup/io/README.txt Sun May 21 11:46:07 2006 @@ -0,0 +1,315 @@ + +=== +I/O +=== + +Export of resources +=================== + +Resources can be exported using the IDOMAdapter adapter. + + >>> from zope.component import getMultiAdapter, getUtility + + + >>> from cpsskins.setup.interfaces import IResourceManager + >>> from cpsskins.setup.io.interfaces import IDOMAdapter + + >>> from xml.dom.minidom import DOMImplementation + >>> dom = DOMImplementation() + + >>> def toXML(obj, title=u'resources', attributes=(), ignored=(), + ... archive=None): + ... document = dom.createDocument(None, title, None) + ... doc = document.documentElement + ... exporter = getMultiAdapter((obj, doc), IDOMAdapter) + ... exporter.archive = archive + ... exporter.document = document + ... exporter.fields_as_attributes = attributes + ... exporter.ignored_fields = ignored + ... exporter.save() + ... return document.toprettyxml(indent=u' ', encoding=u'utf-8') + + >>> root = getRootFolder() + + >>> from cpsskins.tests.setup import addThemeManager + >>> from cpsskins.tests.setup import makeSite + >>> tmutil = addThemeManager(root, makeSite(root)) + + >>> resources = getUtility(IResourceManager) + +Export of styles +---------------- + + >>> from cpsskins.standard.formats.style import Style + >>> resource = Style() + >>> resource[u'div.body'] = {'color': u'red', 'border': u'none'} + + >>> print toXML(resource, u'styles') + <?xml version="1.0" encoding="utf-8"?> + <styles> + <style id="..."> + <rule selector="div.body"> + <property name="color" value="red"/> + <property name="border" value="none"/> + </rule> + </style> + </styles> + <BLANKLINE> + +Export of settings +------------------ + + >>> style = Style() + >>> style[u'h1'] = {'color': 'red'} + >>> root[u'style-1'] = style + >>> resources.register(name=u'style1', title=u'Style 1', resource=style) + <Setting: cpsskins://[EMAIL PROTECTED]> + +When exporting settings, the resource's own type is skipped, we write: + + <setting ... type="format-style"> + <rule> + ... + </rule> + </setting> + +instead of: + + <setting ... type="format-style"> + <style id="..."> + <rule> + ... + </rule> + </style> + </setting> + + >>> setting = resources.lookup(u'cpsskins://[EMAIL PROTECTED]') + >>> print toXML(setting, u'settings') + <?xml version="1.0" encoding="utf-8"?> + <settings> + <setting custom="False" name="style1" title="Style 1" type="format-style"> + <rule selector="h1"> + <property name="color" value="red"/> + </rule> + </setting> + </settings> + <BLANKLINE> + +Export of relations +------------------- + +Monadic relations: + + >>> from cpsskins.relations import MonadicRelation, Predicate + >>> from cpsskins.standard.portlets.actions.portlet import Actions + + >>> relation = MonadicRelation(predicate=Predicate(u'_ A'), + ... first=Actions(u'Actions portlet')) + + >>> print toXML(relation, u'relations') + <?xml version="1.0" encoding="utf-8"?> + <relations> + <monad predicate="_ A"> + <relate uri="cpsskins://canvas-portlet-standard.actions:..."/> + </monad> + </relations> + <BLANKLINE> + + +Dyadic relations: + + >>> from cpsskins.standard.portlets.breadcrumbs.portlet import Breadcrumbs + >>> from cpsskins.relations import DyadicRelation + + >>> relation = DyadicRelation(predicate=Predicate(u'_ B _'), + ... first=Actions(u'Actions portlet'), + ... second=Breadcrumbs(u'Breadcrumbs portlet')) + + >>> print toXML(relation, u'relations') + <?xml version="1.0" encoding="utf-8"?> + <relations> + <dyad predicate="_ B _"> + <relate uri="cpsskins://canvas-portlet-standard.actions:..."/> + <relate uri="cpsskins://canvas-portlet-standard.breadcrumbs:..."/> + </dyad> + </relations> + <BLANKLINE> + + +Triadic relations: + + >>> from cpsskins.relations import TriadicRelation + >>> from cpsskins.elements.slot import Slot + + >>> relation = TriadicRelation(predicate=Predicate(u'_ C _ D _'), + ... first=Actions(u'Actions portlet'), + ... second=Breadcrumbs(u'Breadcrumbs portlet'), + ... third=Slot(slot=u'slotA')) + + >>> print toXML(relation, u'relations') + <?xml version="1.0" encoding="utf-8"?> + <relations> + <triad predicate="_ C _ D _"> + <relate uri="cpsskins://canvas-portlet-standard.actions:..."/> + <relate uri="cpsskins://canvas-portlet-standard.breadcrumbs:..."/> + <relate uri="cpsskins://canvas-slot:slotA"/> + </triad> + </relations> + <BLANKLINE> + + +Export of elements +------------------ + + >>> from cpsskins.elements.pageblock import PageBlock + >>> pageblock = PageBlock(u'Some page block') + + >>> root['pageblock'] = pageblock + + >>> from cpsskins.elements.cell import Cell + >>> cell1 = Cell(u'Some cell 1') + >>> cell2 = Cell(u'Some cell 2') + + >>> pageblock[u'cell1'] = cell1 + >>> pageblock[u'cell2'] = cell2 + + >>> from cpsskins.elements.slot import Slot + >>> slot = Slot(u'Some slot', slot=u'slot1') + >>> pageblock[u'cell1'][u'slot'] = slot + + >>> print toXML(pageblock, u'elements', (u'title', u'description'), + ... (u'slot',)) + <?xml version="1.0" encoding="utf-8"?> + <elements> + <pageblock id="..." title="Some page block"> + <cell id="..." title="Some cell 1"> + <slot description="" id="slot1" title="Some slot"/> + </cell> + <cell id="..." title="Some cell 2"/> + </pageblock> + </elements> + <BLANKLINE> + + +Export of container elements +---------------------------- + + >>> from cpsskins.tests.setup import addThemeManager, addThemeSkeleton + >>> root = getRootFolder() + >>> theme = addThemeSkeleton(tmutil) + + >>> print toXML(theme, u'themes', (u'title', ), (u'slot',)) + <?xml version="1.0" encoding="utf-8"?> + <themes> + <theme id="..." title="A theme"> + <themepage id="..." title="A page"> + <pageblock id="..." title="A page block"> + <cell id="..." title="A cell"/> + </pageblock> + </themepage> + </theme> + </themes> + <BLANKLINE> + +Export of portlets +------------------ + + >>> portlet = Actions(title=u'Action portlet', category=u'zmi_views') + + >>> print toXML(portlet, u'portlets', (u'title', )) + <?xml version="1.0" encoding="utf-8"?> + <portlets> + <portlet id="..." title="Action portlet" type="standard.actions"> + <category value="zmi_views"/> + </portlet> + </portlets> + <BLANKLINE> + +Export of display elements +------------------------- + + >>> from cpsskins.standard.displays.area import Area + >>> area = Area() + + >>> print toXML(area, u'displays') + <?xml version="1.0" encoding="utf-8"?> + <displays> + <area id="..."/> + </displays> + <BLANKLINE> + +Export of format elements +------------------------- + + >>> from cpsskins.standard.formats.effect import Effect + >>> effect = Effect(width=100, height=80) + + >>> print toXML(effect, u'formats') + <?xml version="1.0" encoding="utf-8"?> + <formats> + <effect id="..."> + <types value=""/> + <format value="PNG"/> + <width value="100"/> + <height value="80"/> + <keep_ratio value="True"/> + </effect> + </formats> + <BLANKLINE> + +Export of binary data +--------------------- + + >>> from cpsskins.standard.portlets.image.portlet import Image + >>> portlet = Image(title=u'Image portlet') + >>> portlet.contentType = u'image/png' + + >>> portlet.data = "\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00x" \ + ... "\x00\x00\x00x\x01\x03\x00\x00\x00\x03\xaa\xa4\x91\x00\x00\x00" \ + ... "\x03PLTE\xff\xff\xff\xa7\xc4\x1b\xc8\x00\x00\x00\x17IDAT8\xcbc`" \ + ... "\x18\x05\xa3`\x14\x8c\x82Q0\nF\x01\xbd\x01\x00\x07\x80\x00\x01:" \ + ... "\xe7\xca\xd4\x00\x00\x00\x00IEND\xaeB`\x82" + + >>> root[u'portlet-1'] = portlet + + >>> from zope.app.file.image import getImageInfo + >>> getImageInfo(portlet.data) + ('image/png', 120, 120) + + >>> archive = {} + + >>> print toXML(portlet, u'portlets', archive=archive) + <?xml version="1.0" encoding="utf-8"?> + <portlets> + <portlet id="..." type="standard.image"> + <title value="Image portlet"/> + <link value=""/> + <data value="..._data_120x120.png"/> + <contentType value="image/png"/> + </portlet> + </portlets> + <BLANKLINE> + + >>> binary_name = u'%s_data_120x120.png' % portlet.identifier + >>> archive[binary_name] == portlet.data + True + +Export of fields +---------------- + + >>> from cpsskins.standard.fields.color import WebColor + >>> blue = WebColor(r=0, g=0, b=255) + >>> root[u'color-1'] = blue + >>> print blue + #0000ff + + >>> archive = {} + >>> print toXML(blue, u'colors', archive=archive) + <?xml version="1.0" encoding="utf-8"?> + <colors> + <color id="..."> + <rgb value="0, 0, 255"/> + </color> + </colors> + <BLANKLINE> + Modified: cpsskins/branches/paris-sprint-2006/setup/manager.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/setup/manager.py (original) +++ cpsskins/branches/paris-sprint-2006/setup/manager.py Sun May 21 11:46:07 2006 @@ -139,9 +139,8 @@ return None obj_type = IType(obj).getTypeName() if type_name != obj_type: - logger.warning("type mismatch: expected '%s' got '%s'.", - obj_type, type_name) - return None + raise TypeError("type mismatch: expected '%s' got '%s'." % \ + (obj_type, type_name)) return obj else: -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins