[Zope-CVS] CVS: Products/AdaptableStorage/gateway_fs - FSUserList.py:1.3.2.1 FSAutoId.py:1.4.2.1 FSClassificationSection.py:1.7.2.1 FSDirectoryItems.py:1.8.2.1 FSFileData.py:1.5.2.1 public.py:1.3.2.1
Christian Zagrodnick
cz@gocept.com
Tue, 21 Jan 2003 03:11:49 -0500
Update of /cvs-repository/Products/AdaptableStorage/gateway_fs
In directory cvs.zope.org:/tmp/cvs-serv25960/gateway_fs
Modified Files:
Tag: zagy-patches
FSAutoId.py FSClassificationSection.py FSDirectoryItems.py
FSFileData.py public.py
Added Files:
Tag: zagy-patches
FSUserList.py
Log Message:
merging HEAD into zagy-patches branch
=== Added File Products/AdaptableStorage/gateway_fs/FSUserList.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.
#
##############################################################################
"""User list gateway, where the user list is stored in a flat file.
$Id: FSUserList.py,v 1.3.2.1 2003/01/21 08:11:14 zagy Exp $
"""
from mapper_public import IGateway, RowSequenceSchema, MappingError
class FSUserList:
__implements__ = IGateway
schema = RowSequenceSchema()
schema.addField('id', 'string', 1)
schema.addField('password', 'string')
schema.addField('roles', 'string:list')
schema.addField('domains', 'string:list')
def __init__(self, fs_conn):
self.fs_conn = fs_conn
def getSchema(self):
return self.schema
def load(self, event):
c = self.fs_conn
p = event.getKeychain()[-1]
assert c.readNodeType(p) == 'f'
text = c.readData(p)
res = []
for line in text.split('\n'):
L = line.strip()
if not L.startswith('#') and ':' in L:
id, password, rolelist, domainlist = L.split(':', 3)
roles = self._splitList(rolelist)
domains = self._splitList(domainlist)
res.append((id, password, roles, domains))
res.sort()
return res, text
def _splitList(self, s):
return tuple([item.strip() for item in s.split(',') if item])
def _joinList(self, items):
for item in items:
if item.strip() != item:
raise MappingError(
"Leading and trailing whitespace are not allowed "
"in roles and domains")
item = item.strip()
if not item:
raise MappingError("Empty role or domain not allowed")
if ',' in item or ':' in item or '\n' in item:
raise MappingError(
"Commas, colons, and newlines are not allowed "
"in roles and domains")
return ','.join(items)
def store(self, event, state):
replace_lines = {}
for id, password, roles, domains in state:
if ':' in id or '\n' in id:
raise MappingError('User IDs cannot have colons or newlines')
if id.startswith('#'):
raise MappingError('User IDs cannot start with #')
if ':' in password or '\n' in password:
raise MappingError('Passwords cannot have colons or newlines')
rolelist = self._joinList(roles)
domainlist = self._joinList(domains)
to_write = '%s:%s:%s:%s' % (id, password, rolelist, domainlist)
replace_lines[id] = to_write
p = event.getKeychain()[-1]
self.fs_conn.writeNodeType(p, 'f')
text = self.fs_conn.readData(p, allow_missing=1)
if text is None:
text = ''
new_lines = []
# Replace / remove users
for line in text.split('\n'):
L = line.strip()
if not L.startswith('#'):
if ':' in L:
name, stuff = L.split(':', 1)
replace = replace_lines.get(name, '')
if replace and replace != L:
new_lines.append(replace)
del replace_lines[name]
# else remove the line
else:
new_lines.append(line)
# Append new users
for line in replace_lines.values():
new_lines.append(line)
# Write it
text = '\n'.join(new_lines)
self.fs_conn.writeData(p, text)
serial = list(state)
serial.sort()
return text
=== Products/AdaptableStorage/gateway_fs/FSAutoId.py 1.4 => 1.4.2.1 ===
--- Products/AdaptableStorage/gateway_fs/FSAutoId.py:1.4 Tue Dec 31 16:47:44 2002
+++ Products/AdaptableStorage/gateway_fs/FSAutoId.py Tue Jan 21 03:11:14 2003
@@ -16,6 +16,8 @@
$Id$
"""
+from types import StringType
+
from mapper_public import IGateway, FieldSchema
class FSAutoId:
@@ -24,6 +26,11 @@
schema = FieldSchema('id', 'string')
+
+ def __init__(self, suffix=''):
+ assert isinstance(suffix, StringType)
+ self.suffix = suffix
+
def getSchema(self):
return self.schema
@@ -41,6 +48,8 @@
def store(self, event, state):
id = self.getIdFrom(event)
- assert state == id, 'Mismatched file ID'
+ if state != id:
+ raise ValueError('Mismatched file ID')
return id
+
=== Products/AdaptableStorage/gateway_fs/FSClassificationSection.py 1.7 => 1.7.2.1 ===
--- Products/AdaptableStorage/gateway_fs/FSClassificationSection.py:1.7 Fri Jan 3 17:04:17 2003
+++ Products/AdaptableStorage/gateway_fs/FSClassificationSection.py Tue Jan 21 03:11:14 2003
@@ -42,21 +42,20 @@
def load(self, event):
c = self.fs_conn
p = event.getKeychain()[-1]
+ classification = {'node_type': c.readNodeType(p)}
text = c.readSection(p, 'classification', '')
- classification = {}
if text:
lines = text.split('\n')
for line in lines:
if '=' in line:
k, v = line.split('=', 1)
classification[k.strip()] = v.strip()
- classification['node_type'] = c.readNodeType(p)
classification['filename'] = self.getIdFrom(event)
return classification, text.strip()
def store(self, event, state):
- classification = state
- items = classification.items()
+ # state is a classification
+ items = state.items()
items.sort()
text = []
for k, v in items:
=== Products/AdaptableStorage/gateway_fs/FSDirectoryItems.py 1.8 => 1.8.2.1 ===
--- Products/AdaptableStorage/gateway_fs/FSDirectoryItems.py:1.8 Tue Dec 31 16:47:44 2002
+++ Products/AdaptableStorage/gateway_fs/FSDirectoryItems.py Tue Jan 21 03:11:14 2003
@@ -19,8 +19,6 @@
from mapper_public import IGateway, RowSequenceSchema
-from FSConnection import WRITE_CONDITIONAL
-
class FSDirectoryItems:
=== Products/AdaptableStorage/gateway_fs/FSFileData.py 1.5 => 1.5.2.1 ===
--- Products/AdaptableStorage/gateway_fs/FSFileData.py:1.5 Tue Dec 31 16:47:44 2002
+++ Products/AdaptableStorage/gateway_fs/FSFileData.py Tue Jan 21 03:11:14 2003
@@ -26,15 +26,19 @@
schema = FieldSchema('data', 'string')
- def __init__(self, fs_conn):
+ def __init__(self, fs_conn, suffix=''):
+ assert isinstance(suffix, StringType)
self.fs_conn = fs_conn
-
+ self.suffix = suffix
+
def getSchema(self):
return self.schema
def load(self, event):
c = self.fs_conn
p = event.getKeychain()[-1]
+ if self.suffix and p.endswith(self.suffix):
+ p = p[:-len(self.suffix)]
assert c.readNodeType(p) == 'f'
state = c.readData(p)
return state, state
@@ -43,7 +47,7 @@
if not isinstance(state, StringType):
raise RuntimeError('Not a string: %s' % repr(state))
c = self.fs_conn
- p = event.getKeychain()[-1]
+ p = event.getKeychain()[-1] + self.suffix
c.writeNodeType(p, 'f')
c.writeData(p, state)
return state
=== Products/AdaptableStorage/gateway_fs/public.py 1.3 => 1.3.2.1 ===
--- Products/AdaptableStorage/gateway_fs/public.py:1.3 Fri Jan 3 17:04:17 2003
+++ Products/AdaptableStorage/gateway_fs/public.py Tue Jan 21 03:11:14 2003
@@ -25,4 +25,4 @@
from FSFileData import FSFileData
from FSProperties import FSProperties
from FSSectionData import FSSectionData
-
+from FSUserList import FSUserList