[Zope-CVS] CVS: Products/AdaptableStorage/gateway_fs - FSProperties.py:1.1 FSClassificationSection.py:1.7 public.py:1.3
Shane Hathaway
shane@zope.com
Fri, 3 Jan 2003 17:04:50 -0500
Update of /cvs-repository/Products/AdaptableStorage/gateway_fs
In directory cvs.zope.org:/tmp/cvs-serv20380/gateway_fs
Modified Files:
FSClassificationSection.py public.py
Added Files:
FSProperties.py
Log Message:
Added PropertyManager support.
=== Added File Products/AdaptableStorage/gateway_fs/FSProperties.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Gateway for storing properties.
$Id: FSProperties.py,v 1.1 2003/01/03 22:04:17 shane Exp $
"""
from mapper_public import IGateway, RowSequenceSchema
token_replacements = {
'\\\\': '\\',
'\\t': '\t',
'\\r': '\r',
'\\n': '\n',
}
def escape(s):
return s.replace('\\', '\\\\').replace('\n', '\\n').replace(
'\r', '\\r').replace('\t', '\\t')
def unescape(s):
res = []
pos = 0
while 1:
p = s.find('\\', pos)
if p >= 0:
res.append(s[pos:p])
token = s[p:p+2]
c = token_replacements.get(token)
if c is not None:
# known escape sequence
res.append(c)
else:
# unknown sequence
res.append(token)
pos = p + 2
else:
res.append(s[pos:])
break
return ''.join(res)
class FSProperties:
__implements__ = IGateway
schema = RowSequenceSchema()
schema.addField('id', 'string', 1)
schema.addField('type', 'string')
schema.addField('data', 'string')
def __init__(self, fs_conn, section='properties'):
self.fs_conn = fs_conn
self.section = section
def getSchema(self):
return self.schema
def load(self, event):
p = event.getKeychain()[-1]
text = self.fs_conn.readSection(p, self.section, '')
res = []
if text:
lines = text.split('\n')
for line in lines:
if '=' in line:
k, v = line.split('=', 1)
if ':' in k:
k, t = k.split(':', 1)
else:
t = 'string'
res.append((k, t, unescape(v)))
res.sort()
return res, tuple(res)
def store(self, event, state):
lines = []
for k, t, v in state:
lines.append('%s:%s=%s' % (k, t, escape(v)))
lines.sort()
text = '\n'.join(lines)
p = event.getKeychain()[-1]
self.fs_conn.writeSection(p, self.section, text)
state = list(state)
state.sort()
return tuple(state)
=== Products/AdaptableStorage/gateway_fs/FSClassificationSection.py 1.6 => 1.7 ===
--- Products/AdaptableStorage/gateway_fs/FSClassificationSection.py:1.6 Tue Dec 31 16:47:44 2002
+++ Products/AdaptableStorage/gateway_fs/FSClassificationSection.py Fri Jan 3 17:04:17 2003
@@ -62,7 +62,6 @@
for k, v in items:
text.append('%s=%s' % (k, v))
text = '\n'.join(text)
- # Write it only if the rest of the subobject is also stored
p = event.getKeychain()[-1]
self.fs_conn.writeSection(p, 'classification', text)
return text.strip()
=== Products/AdaptableStorage/gateway_fs/public.py 1.2 => 1.3 ===
--- Products/AdaptableStorage/gateway_fs/public.py:1.2 Wed Dec 4 23:18:07 2002
+++ Products/AdaptableStorage/gateway_fs/public.py Fri Jan 3 17:04:17 2003
@@ -23,5 +23,6 @@
from FSConnection import FSConnection
from FSDirectoryItems import FSDirectoryItems
from FSFileData import FSFileData
+from FSProperties import FSProperties
from FSSectionData import FSSectionData