[Zope-CVS] CVS: Products/Ape/lib/apelib/core - events.py:1.6.2.6
gateways.py:1.7.2.5 interfaces.py:1.9.2.6 io.py:1.6.2.6
mapper.py:1.4.4.4 oidgen.py:1.1.2.3
Shane Hathaway
shane at zope.com
Sat Dec 20 23:24:34 EST 2003
Update of /cvs-repository/Products/Ape/lib/apelib/core
In directory cvs.zope.org:/tmp/cvs-serv18412/lib/apelib/core
Modified Files:
Tag: ape-0_8-branch
events.py gateways.py interfaces.py io.py mapper.py oidgen.py
Log Message:
Continued cleanup after refactoring the interfaces. See CHANGES.txt.
All tests now pass except for the SQL tests.
=== Products/Ape/lib/apelib/core/events.py 1.6.2.5 => 1.6.2.6 ===
--- Products/Ape/lib/apelib/core/events.py:1.6.2.5 Sat Dec 20 02:31:04 2003
+++ Products/Ape/lib/apelib/core/events.py Sat Dec 20 23:24:03 2003
@@ -67,13 +67,12 @@
"""Object storing event.
"""
__implements__ = interfaces.IStoreEvent
- overwrite = False
+ is_new = False
- def __init__(self, conf, mapper, oid, connections, classification,
- overwrite):
+ def __init__(self, conf, mapper, oid, connections, classification, is_new):
GatewayEvent.__init__(
self, conf, mapper, oid, connections, classification)
- self.overwrite = overwrite
+ self.is_new = is_new
class SDEvent (MapperEvent):
=== Products/Ape/lib/apelib/core/gateways.py 1.7.2.4 => 1.7.2.5 ===
--- Products/Ape/lib/apelib/core/gateways.py:1.7.2.4 Fri Dec 19 21:52:47 2003
+++ Products/Ape/lib/apelib/core/gateways.py Sat Dec 20 23:24:03 2003
@@ -18,7 +18,7 @@
import time
-from interfaces import IGateway, StoreError
+from interfaces import IGateway, ConflictError
class CompositeGateway:
@@ -115,8 +115,8 @@
return self.data[event.oid]
def store(self, event, data):
- if not event.overwrite and self.data.has_key(event.oid):
- raise StoreError("Conflict on OID %s" % repr(event.oid))
+ if event.is_new and self.data.has_key(event.oid):
+ raise ConflictError(event.oid)
h = time.time()
self.data[event.oid] = (data, h)
return h
=== Products/Ape/lib/apelib/core/interfaces.py 1.9.2.5 => 1.9.2.6 ===
--- Products/Ape/lib/apelib/core/interfaces.py:1.9.2.5 Sat Dec 20 02:31:04 2003
+++ Products/Ape/lib/apelib/core/interfaces.py Sat Dec 20 23:24:03 2003
@@ -40,6 +40,12 @@
class ConfigurationError(Exception):
"""Invalid mapper configuration"""
+try:
+ from ZODB.POSException import ConflictError
+except ImportError:
+ class ConflictError(Exception):
+ """Conflicting OIDs or data"""
+
class IClassFactory(Interface):
"""Class finder."""
@@ -136,11 +142,12 @@
class IStoreEvent (IGatewayEvent):
"""Interface for events involved in storing objects."""
- overwrite = Attribute(__doc__="""True if the gateway may overwrite.
+ is_new = Attribute(__doc__="""True if the object is new.
- When this attribute is true, gateways should overwrite existing
- data. When it is false, gateways should not overwrite existing
- data and instead raise a conflict error.
+ When this attribute is true, gateways should not overwrite
+ existing data but instead raise a ConflictError if something is in
+ the way. When it is false, gateways should overwrite existing
+ data.
""")
@@ -436,7 +443,7 @@
one place.
"""
- #root_oid = Attribute(__doc__="The OID to use at the root")
+ root_oid = Attribute(__doc__="The OID to use for the root")
def new_oid(event, name, stored):
"""Returns a new oid.
=== Products/Ape/lib/apelib/core/io.py 1.6.2.5 => 1.6.2.6 ===
--- Products/Ape/lib/apelib/core/io.py:1.6.2.5 Sat Dec 20 02:31:04 2003
+++ Products/Ape/lib/apelib/core/io.py Sat Dec 20 23:24:03 2003
@@ -23,7 +23,7 @@
from events \
import DatabaseInitEvent, GatewayEvent, LoadEvent, StoreEvent, \
SerializationEvent, DeserializationEvent
-from interfaces import ITPCConnection, IObjectDatabase, IMapperConfiguration
+from interfaces import IMapperConfiguration, ITPCConnection, IObjectDatabase
class ClassifiedState:
@@ -35,26 +35,11 @@
self.mapper_name = mapper_name
-class MapperConfiguration:
- __implements__ = IMapperConfiguration
- mappers = None
- classifier = None
- oid_gen = None
-
- def __init__(self, mappers, classifier, oid_gen):
- self.mappers = mappers
- self.classifier = classifier
- self.oid_gen = oid_gen
-
- def check(self):
- for name, mapper in self.mappers.items():
- mapper.check(name)
-
-
class GatewayIO:
"""Gateway operations facade."""
def __init__(self, conf, connections):
+ assert IMapperConfiguration.isImplementedBy(conf), conf
self.conf = conf
self.conn_map = connections
# Sort the connections by sort key. Use an extra index to avoid
@@ -120,10 +105,10 @@
cs = ClassifiedState(state, classification, mapper_name)
return event, cs, hash_value
- def store(self, oid, classified_state, overwrite):
+ def store(self, oid, classified_state, is_new):
mapper = self.conf.mappers[classified_state.mapper_name]
event = StoreEvent(self.conf, mapper, oid, self.conn_map,
- classified_state.classification, overwrite)
+ classified_state.classification, is_new)
new_hash = mapper.gateway.store(event, classified_state.state)
self.conf.classifier.store(event, classified_state.classification)
return event, new_hash
@@ -144,6 +129,8 @@
"""Object system (de)serialization facade."""
def __init__(self, conf, obj_db):
+ assert IMapperConfiguration.isImplementedBy(conf), conf
+ assert IObjectDatabase.isImplementedBy(obj_db), obj_db
self.conf = conf
self.obj_db = obj_db
@@ -293,4 +280,3 @@
def new_oid(self):
# Should be called only while exporting
return self.gw_io.new_oid()
-
=== Products/Ape/lib/apelib/core/mapper.py 1.4.4.3 => 1.4.4.4 ===
--- Products/Ape/lib/apelib/core/mapper.py:1.4.4.3 Sat Dec 20 02:31:04 2003
+++ Products/Ape/lib/apelib/core/mapper.py Sat Dec 20 23:24:03 2003
@@ -80,3 +80,21 @@
msg = '%s != %s' % (ss, gs)
raise ConfigurationError(
'Mapper %s: Mismatched schemas. %s' % (my_name, msg))
+
+
+class MapperConfiguration:
+ """Collects the mapper configuration with a classifier and OID generator.
+ """
+ __implements__ = interfaces.IMapperConfiguration
+ mappers = None
+ classifier = None
+ oid_gen = None
+
+ def __init__(self, mappers, classifier, oid_gen):
+ self.mappers = mappers
+ self.classifier = classifier
+ self.oid_gen = oid_gen
+
+ def check(self):
+ for name, mapper in self.mappers.items():
+ mapper.check(name)
=== Products/Ape/lib/apelib/core/oidgen.py 1.1.2.2 => 1.1.2.3 ===
--- Products/Ape/lib/apelib/core/oidgen.py:1.1.2.2 Fri Dec 19 21:52:47 2003
+++ Products/Ape/lib/apelib/core/oidgen.py Sat Dec 20 23:24:03 2003
@@ -24,6 +24,11 @@
"""
__implements__ = IOIDGenerator
+ root_oid = "/_root"
+
+ def __init__(self, root_oid="/_root"):
+ self.root_oid = root_oid
+
def new_oid(self, event, name, stored):
if name is None:
raise MappingError('Path OIDs require a name')
@@ -42,12 +47,16 @@
"""
__implements__ = IOIDGenerator
- counter = 0
+ root_oid = '0'
+ counter = 1
+
+ def __init__(self, root_oid="0"):
+ self.root_oid = root_oid
def new_oid(self, event, name, stored):
if not stored:
raise MappingError('Serial OIDs must be stored')
- self.counter += 1
oid = str(self.counter)
+ self.counter += 1
return oid
More information about the Zope-CVS
mailing list