Changeset 5011


Ignore:
Timestamp:
4 Feb 2010, 17:11:39 (15 years ago)
Author:
uli
Message:

Get rid of references to waeup.sirp.university.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/importexport.txt

    r4965 r5011  
    1818    >>> grok.testing.grok('waeup')
    1919
     20Furthermore we need something to import/export. As only pickable
     21classes are importable/exportable and these have to be defined in some
     22globally reachable module, we first define some silly object in
     23filesystem and adjust the path to lookup modules:
     24
     25    >>> import os
     26    >>> import sys
     27    >>> os.mkdir('stoneage')
     28    >>> old_sys_path = sys.path
     29    >>> open(os.path.join('stoneage', '__init__.py'), 'wb').write(
     30    ... """
     31    ... class Cave(object):
     32    ...   name = 'Unnamed cave'
     33    ...   dinoports = 2
     34    ... """)
     35    >>> sys.path.append(os.getcwd())
     36
     37Now we can import stoneage.Cave objects.
     38
    2039
    2140Exporting XML
     
    2847i.e. an in-memory file.
    2948
    30 To show this basic functionality provided for all XML exportable
    31 objects, we choose faculties.
     49We can export caves. First we create a cave:
    3250
    33 We can export faculties. First we create a faculty::
    34 
    35     >>> from waeup.sirp.university.faculty import Faculty
    36     >>> myfaculty = Faculty()
    37     >>> myfaculty.name = 'My very faculty.'
     51    >>> from stoneage import Cave
     52    >>> mycave = Cave()
     53    >>> mycave.name = 'Freds Cave'
     54    >>> mycave.dinoports = 1
    3855
    3956Exporting plain XML
     
    4461
    4562    >>> from waeup.sirp.interfaces import IWAeUPXMLExporter
    46     >>> exporter = IWAeUPXMLExporter(myfaculty)
     63    >>> exporter = IWAeUPXMLExporter(mycave)
    4764    >>> exporter
    4865    <waeup.sirp.utils.importexport.XMLExporter object at 0x...>
     
    6885    <?xml version="1.0" encoding="utf-8" ?>
    6986    <pickle>
    70       <initialized_object>
     87      <object>
    7188    ...
    7289    </pickle>
    7390
    74 Clean up::
    75 
    76     >>> import os
    77     >>> os.unlink('myexport.xml')
    7891
    7992Importing XML
     
    8295We can generate objects from XML.
    8396
    84 Let's create a faculty instance, that we want to be restored
    85 afterwards::
     97We change the name of the cave:
    8698
    87     >>> from waeup.sirp.university.faculty import Faculty
    88     >>> myfaculty = Faculty()
    89     >>> myfaculty.name = 'My very faculty.'
     99    >>> mycave.name = 'Another name'
    90100
    91 We create an XML dump of this object::
    92 
    93     >>> from waeup.sirp.interfaces import IWAeUPXMLExporter
    94     >>> exporter = IWAeUPXMLExporter(myfaculty)
    95     >>> result = exporter.export('myexport.xml')
    96 
    97 We change the name of the faculty::
    98 
    99     >>> myfaculty.name = 'Another name'
    100 
    101 Now we create an importer for that file::
     101Now we create an importer for that object:
    102102
    103103    >>> from waeup.sirp.interfaces import IWAeUPXMLImporter
    104     >>> importer = IWAeUPXMLImporter(myfaculty)
     104    >>> importer = IWAeUPXMLImporter(mycave)
    105105
    106106Importing from filenames
     
    111111    >>> new_obj = importer.doImport('myexport.xml')
    112112
    113 The object created is indeed a faculty::
     113The object created is indeed a cave::
    114114
    115115    >>> new_obj
    116     <waeup.sirp.university.faculty.Faculty object at 0x...>
     116    <stoneage.Cave object at 0x...>
    117117
    118118    >>> new_obj.name
    119     'My very faculty.'
     119    'Freds Cave'
    120120
    121121The new object is really a new object::
    122122
    123     >>> new_obj is myfaculty
     123    >>> new_obj is mycave
    124124    False
    125125
     
    135135
    136136    >>> new_obj
    137     <waeup.sirp.university.faculty.Faculty object at 0x...>
     137    <stoneage.Cave object at 0x...>
    138138
    139139Clean up::
    140140
    141141    >>> import os
     142    >>> import shutil
     143    >>> sys.path = old_sys_path
    142144    >>> os.unlink('myexport.xml')
     145    >>> shutil.rmtree('stoneage')
Note: See TracChangeset for help on using the changeset viewer.