def setUp(self): database = RWDatabase(100, 100) self.database = database self.root = database.get_handler('.') file = lfs.make_file('tests/toto.txt') try: file.write('I am Toto\n') finally: file.close()
class Clients(CSVFile): columns = ['client_id', 'name', 'email', 'registration_date'] schema = { 'client_id': Integer, 'name': Unicode, 'email': String, 'registration_date': Date } if __name__ == '__main__': rw_database = RWDatabase() clients = rw_database.get_handler("clients.csv", Clients) # Access a column by its name row = clients.get_row(0) # Now 'update_row' expects the values to be of the good type clients.update_row(0, registration_date=date(2004, 11, 10)) # So is for the 'add_row' method clients.add_row( [250, u'J. David Ibanez', '*****@*****.**', date(2007, 1, 1)]) print clients.to_str()
# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the: # Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, # Boston, MA 02110-1301, USA # Import from itools from itools.handlers import RWDatabase from itools.loop import Loop from itools.web import WebServer, RootResource, BaseView class MyView(BaseView): access = True def GET(self, resource, context): context.set_content_type('text/plain') return 'Hello World' class MyRoot(RootResource): default_view_name = 'my_view' my_view = MyView() if __name__ == '__main__': root = MyRoot() server = WebServer(root) server.listen('localhost', 8080) server.database = RWDatabase() loop = Loop() loop.run()
# You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # Import from the Standard Library from unittest import TestCase, main # Import from itools from itools.core import start_subprocess from itools.csv import Table from itools.datatypes import Unicode from itools.handlers import ro_database from itools.handlers import RWDatabase, make_git_database from itools.handlers import TextFile, ConfigFile, TGZFile from itools.fs import lfs rw_database = RWDatabase(fs=lfs) class Agenda(Table): record_properties = { 'firstname': Unicode(is_indexed=True, multiple=False), 'lastname': Unicode(multiple=False) } class StateTestCase(TestCase): def test_abort(self): handler = rw_database.get_handler('tests/hello.txt') self.assertEqual(handler.data, u'hello world\n') handler.set_data(u'bye world\n')