# HG changeset patch # User paulb # Date 1132521549 0 # Node ID 7d20d8b4809ee39b495d754a69929cfdf0b93348 # Parent 8128e3584507ec10efb87294589923d9303be818 [project @ 2005-11-20 21:19:09 by paulb] Changed the result of the lock method. diff -r 8128e3584507 -r 7d20d8b4809e docs/directory-repository.html --- a/docs/directory-repository.html Sun Nov 20 21:19:02 2005 +0000 +++ b/docs/directory-repository.html Sun Nov 20 21:19:09 2005 +0000 @@ -27,6 +27,6 @@ process.
One might choose to initialise a repository in the initialisation method of a resource:
# Inside a module defining a resource...
class MyResource:
def __init__(self):
repository_dir = os.path.join(os.path.split(__file__)[0], "repository")
self.repository = DirectoryRepository(repository_dir, "iso-8859-1")
Here, the repository will reside alongside the resource's module in the filesystem.
One might use a repository with a session-like API as follows:
# Given a name and some data, possibly provided in user input, store the data in the repository.
repository[name] = data
Note that DirectoryRepository
places some restrictions on the values that can be used as keys in the
session-like API since each key must correspond to a filename within
-the designated directory.
The DirectoryRepository
class also provides various methods to support access to files in the repository using standard file objects and methods:
# Given a name and some data...
repository.lock(name)
f = open(repository.full_path(name), "wb")
try:
f.write(data)
finally:
f.close()
repository.unlock(name)
The usage of try
and finally
+the designated directory.
The DirectoryRepository
class also provides various methods to support access to files in the repository using standard file objects and methods:
# Given a name and some data...
edit_path = repository.lock(name)
f = open(edit_path, "wb")
try:
f.write(data)
finally:
f.close()
repository.unlock(name)
The usage of try
and finally
clauses is important to ensure that files are not left locked and
-inaccessible due to unhandled exceptions being raised. See the API documentation for the DirectoryRepository
class for more information about the available methods and their behaviour.