[Zope-CVS] CVS: Products/AdaptableStorage/serial_ofs - MetaTypeClassifier.py:1.12
Shane Hathaway
shane@zope.com
Tue, 4 Feb 2003 23:59:50 -0500
Update of /cvs-repository/Products/AdaptableStorage/serial_ofs
In directory cvs.zope.org:/tmp/cvs-serv22769/serial_ofs
Modified Files:
MetaTypeClassifier.py
Log Message:
Added an automatic filename extensions feature to FSConnection and
corresponding unit tests. Also cleaned up minor details in FSConnection.
=== Products/AdaptableStorage/serial_ofs/MetaTypeClassifier.py 1.11 => 1.12 ===
--- Products/AdaptableStorage/serial_ofs/MetaTypeClassifier.py:1.11 Tue Dec 31 16:47:50 2002
+++ Products/AdaptableStorage/serial_ofs/MetaTypeClassifier.py Tue Feb 4 23:59:18 2003
@@ -16,8 +16,6 @@
$Id$
"""
-import os
-
from Acquisition import aq_base
from OFS.ObjectManager import ObjectManager
@@ -34,6 +32,7 @@
self.gw = gw
self.key_to_res = {}
self.ext_to_mt = {}
+ self.mt_to_ext = {}
self.fmt_to_mt = {}
self.mt_to_mapper = {}
@@ -42,19 +41,28 @@
def register(self, meta_type, mapper_name, extensions=()):
+ """Registers a mapper to handle a Zope meta_type."""
for ext in extensions:
if not ext.startswith('.'):
ext = '.' + ext
ext = ext.lower()
self.ext_to_mt[ext] = meta_type
+ if extensions:
+ self.mt_to_ext[meta_type] = extensions[0]
self.mt_to_mapper[meta_type] = mapper_name
def registerKey(self, meta_type, mapper_name, key):
+ """Registers a mapper to handle a specific path.
+
+ For example, the application object mapper usually handles
+ the path '/'.
+ """
self.key_to_res[key] = ({'meta_type': meta_type}, mapper_name)
def registerDefaultLoader(self, meta_type, mapper_name, isdir):
+ """Registers a mapper to load unknown files or directories."""
if isdir:
ext = '<directory>'
else:
@@ -64,6 +72,7 @@
def registerDefaultStorage(self, meta_type, mapper_name, folderish):
+ """Registers a mapper to store unknown objects."""
if folderish:
fmt = 'folder'
else:
@@ -73,6 +82,7 @@
def classifyObject(self, value, keychain):
+ """Chooses a mapper and classification for storing an object."""
res = self.key_to_res.get(keychain[-1])
if res is not None:
return res
@@ -96,10 +106,14 @@
klass = value.__class__
ci = '%s:%s' % (klass.__module__, klass.__name__)
classification = {'meta_type': mt, 'class_name': ci}
+ ext = self.mt_to_ext.get(mt)
+ if ext:
+ classification['extension'] = ext
return classification, mapper_name
def classifyState(self, event):
+ """Chooses a mapper and classification for loading an object."""
keychain = event.getKeychain()
res = self.key_to_res.get(keychain[-1])
if res is not None:
@@ -113,9 +127,10 @@
mt = self.ext_to_mt.get('<directory>', 'Folder')
elif t == 'f':
# File
- filename = classification.get('filename')
- if filename:
- name, ext = os.path.splitext(filename)
+ ext = classification.get('extension')
+ if ext:
+ if not ext.startswith('.'):
+ ext = '.' + ext
mt = self.ext_to_mt.get(ext.lower())
if not mt:
mt = self.ext_to_mt.get('<file>', 'File')
@@ -131,5 +146,6 @@
def store(self, event, classification):
+ """Stores the classification of an object."""
return self.gw.store(event, classification)