本文整理汇总了Python中transaction.savepoint函数的典型用法代码示例。如果您正苦于以下问题:Python savepoint函数的具体用法?Python savepoint怎么用?Python savepoint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了savepoint函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __iter__
def __iter__(self):
count = 0
for item in self.previous:
count = (count + 1) % self.every
if count == 0:
transaction.savepoint(optimistic=True)
yield item
示例2: _initFolders
def _initFolders( self ):
from Products.CMFCore.PortalFolder import PortalFolder
self.connection = makeConnection()
try:
r = self.connection.root()
a = Application()
r['Application'] = a
self.root = a
responseOut = self.responseOut = cStringIO.StringIO()
self.app = makerequest( self.root, stdout=responseOut )
self.app._setObject( 'folder1', PortalFolder( 'folder1' ) )
self.app._setObject( 'folder2', PortalFolder( 'folder2' ) )
folder1 = getattr( self.app, 'folder1' )
folder2 = getattr( self.app, 'folder2' )
manage_addFile( folder1, 'file'
, file='', content_type='text/plain')
# Hack, we need a _p_mtime for the file, so we make sure that it
# has one. We use a subtransaction, which means we can rollback
# later and pretend we didn't touch the ZODB.
transaction.savepoint(optimistic=True)
except:
self.connection.close()
raise
return self.app._getOb( 'folder1' ), self.app._getOb( 'folder2' )
示例3: testRenameLastObject
def testRenameLastObject(self):
# Renaming should not change position
transaction.savepoint(optimistic=True) # make rename work
self.folder.manage_renameObjects(['baz'], ['bedrock'])
self.assertEqual(self.folder.getObjectPosition('foo'), 0)
self.assertEqual(self.folder.getObjectPosition('bar'), 1)
self.assertEqual(self.folder.getObjectPosition('bedrock'), 2)
示例4: test_move_cant_delete_source
def test_move_cant_delete_source( self ):
#
# This test fails on Zope's earlier than 2.7.3 because of the
# changes required to 'OFS.CopytSupport.manage_pasteObjects'
# which must pass 'validate_src' of 2 to '_verifyObjectPaste'
# to indicate that the object is being moved, rather than
# simply copied.
#
# If you are running with such a Zope, this test will fail,
# because the move (which should raise Unauthorized) will be
# allowed.
#
from AccessControl.Permissions import delete_objects as DeleteObjects
from Products.CMFCore.PortalFolder import PortalFolder
folder1, folder2 = self._initFolders()
folder1.manage_permission( DeleteObjects, roles=(), acquire=0 )
folder1._setObject( 'sub', PortalFolder( 'sub' ) )
transaction.savepoint(optimistic=True) # get a _p_jar for 'sub'
self.app.portal_types = DummyTypesTool()
def _no_delete_objects(permission, object, context):
return permission != DeleteObjects
self._initPolicyAndUser( c_lambda=_no_delete_objects )
cookie = folder1.manage_cutObjects( ids=( 'sub', ) )
self._assertCopyErrorUnauth( folder2.manage_pasteObjects
, cookie
, ce_regex='Insufficient Privileges'
+ '.*%s' % DeleteObjects
)
示例5: testOnItemRenamed
def testOnItemRenamed(self):
"""Test notification when an item is renamed."""
## Since there is currently no special rule for this event, we
## should not send anything.
portal = self.portal
ntool = getToolByName(portal, NTOOL_ID)
changeProperty = lambda key, value: \
ntool.manage_changeProperties(**{key: value})
self.login('manager')
## Enable some rules just to make sure that none of them
## match.
changeProperty('item_creation_notification_enabled', True)
changeProperty('on_item_creation_users', ['* :: *'])
changeProperty('on_item_creation_mail_template',
['* :: string:creation_mail_notification'])
changeProperty('item_modification_notification_enabled', True)
changeProperty('on_item_modification_users', ['* :: *'])
changeProperty('on_item_modification_mail_template',
['* :: string:modification_mail_notification'])
changeProperty('item_wf_transition_notification_enabled', True)
changeProperty('on_wf_transition_modification_users', ['* :: *'])
changeProperty('on_wf_transition_modification_mail_template',
['* :: string:workflow_mail_notification'])
transaction.savepoint() ## We need this to cut/paste objects.
portal.folder.manage_renameObjects(('document1', ),
('renamed-document', ))
self.failUnlessSent(0)
示例6: test18_retrieveObjectWhichHasBeenReplaced
def test18_retrieveObjectWhichHasBeenReplaced(self):
portal_repo = self.portal.portal_repository
fol = self.portal.fol
doc1 = fol.doc1
doc2 = fol.doc2
# save change no 1
fol.setTitle('v1 of fol')
doc1.setTitle("v1 of doc1")
doc2.setTitle("v1 of doc2")
portal_repo.applyVersionControl(doc1, comment='first save')
portal_repo.applyVersionControl(doc2, comment='first save')
transaction.savepoint(optimistic=True)
fol.manage_renameObjects(['doc1','doc2'],['doc1_renamed', 'doc1'])
doc1 = fol.doc1_renamed
doc2 = fol.doc1
doc1.setTitle('v2 of doc1_renamed')
doc2.setTitle('v2 of doc1 (was doc2)')
portal_repo.save(doc1, comment='second save')
portal_repo.save(doc2, comment='second save')
retrieved_data = portal_repo.retrieve(doc1, 0)
ret_doc = retrieved_data.object
self.assertEqual(ret_doc.getId(), 'doc1')
self.assertEqual(ret_doc.Title(), 'v1 of doc1')
portal_repo.revert(doc1, 0)
rev_doc = fol.doc1_renamed
self.assertEqual(rev_doc.getId(), 'doc1_renamed')
self.assertEqual(rev_doc.Title(), 'v1 of doc1')
示例7: test_index_html_with_304_and_caching
def test_index_html_with_304_and_caching( self ):
# See collector #355
self._setupCachingPolicyManager(DummyCachingManager())
original_len = len(self.RESPONSE.headers)
path, ref = self._extractFile()
from webdav.common import rfc1123_date
self.root.image = self._makeOne( 'test_image', 'test_image.gif' )
image = self.root.image
transaction.savepoint(optimistic=True)
mod_time = image.modified()
self.REQUEST.environ[ 'IF_MODIFIED_SINCE'
] = '%s;' % rfc1123_date( mod_time+1 )
data = image.index_html( self.REQUEST, self.RESPONSE )
self.assertEqual( data, '' )
self.assertEqual( self.RESPONSE.getStatus(), 304 )
headers = self.RESPONSE.headers
self.failUnless(len(headers) >= original_len + 3)
self.failUnless('foo' in headers.keys())
self.failUnless('bar' in headers.keys())
self.assertEqual(headers['test_path'], '/test_image')
示例8: test23_RegistryBasesNotVersionedOrRestored
def test23_RegistryBasesNotVersionedOrRestored(self):
portal_repo = self.portal.portal_repository
fol = self.portal.fol
fol.setTitle("v1")
# Make it a component registry with bases
base = aq_base(self.portal.getSiteManager())
components = PersistentComponents()
components.__bases__ = (base,)
fol.setSiteManager(components)
portal_repo.applyVersionControl(fol)
broken_iface = broken.find_global(
'never_gonna_be_real', 'IMissing',
Broken=ZODB.interfaces.IBroken, type=InterfaceClass)
sys.modules[broken_iface.__module__] = module = imp.new_module(
broken_iface.__module__)
module.IMissing = broken_iface
# add a broken registrsation but do a savepoint before
# breaking the interfaces to simulate a broken registrion from
# a previous commit
base.registerUtility(component=None, provided=broken_iface)
transaction.savepoint(optimistic=True)
del sys.modules[broken_iface.__module__]
fol.setTitle("v2")
# If an attempt was made to pickle the parent registry's
# broken registration we would see an error here
portal_repo.save(fol)
self.assertEqual(self.portal.fol.Title(), "v2")
self.assertTrue(
self.portal.fol.getSiteManager().__bases__[0] is base)
示例9: handle_rename
def handle_rename(self, action):
data, errors = self.extractData()
if errors:
return
parent = aq_parent(aq_inner(self.context))
sm = getSecurityManager()
if not sm.checkPermission('Copy or Move', parent):
raise Unauthorized(_(u'Permission denied to rename ${title}.',
mapping={u'title': self.context.title}))
oldid = self.context.getId()
newid = data['new_id']
newid = INameChooser(parent).chooseName(newid, self.context)
context_state = getMultiAdapter(
(self.context, self.request), name='plone_context_state')
if context_state.is_default_page():
parent.setDefaultPage(newid)
# Requires cmf.ModifyPortalContent permission
self.context.title = data['new_title']
# Requires zope2.CopyOrMove permission
parent.manage_renameObjects([oldid, ], [str(newid), ])
transaction.savepoint(optimistic=True)
notify(ObjectModifiedEvent(self.context))
IStatusMessage(self.request).add(
_(u"Renamed '${oldid}' to '${newid}'.", mapping={
u'oldid': oldid, u'newid': newid}))
self.request.response.redirect(self.context.absolute_url())
示例10: updateKupu
def updateKupu(context):
# Ordinarily, GenericSetup handlers check for the existence of XML files.
# Here, we are not parsing an XML file, but we use this text file as a
# flag to check that we actually meant for this import step to be run.
# The file is found in profiles/default.
if context.readDataFile('collective.imagetags_kupu.txt') is None:
return
# Add additional setup code here
out = StringIO()
portal = getSite()
# Get kupu tool and update its paragraph_styles property
kt = getToolByName(portal, 'kupu_library_tool', None)
if kt:
new_style = 'Show tags|img|imagetags-show'
styles = kt.getParagraphStyles()
if not new_style in styles:
styles.append(new_style)
kt.configure_kupu(parastyles=styles)
transaction.savepoint()
print >> out, "Updated paragraph_styles in kupu: %s" % new_style
else:
print >> out, "kupu already has %s in paragraph_styles" % new_style
context.getLogger("collective.imagetags").info(out.getvalue())
return out.getvalue()
示例11: _install_zope
def _install_zope(self, db):
"""Install a fresh Zope inside the new test DB. Eventually
install an application afterwards.
"""
# Create the "application"
newSecurityManager(None, AccessControl.User.system)
connection = db.open()
root = connection.root()
root['Application'] = OFS.Application.Application()
app = root['Application']
# Do a savepoint to get a _p_jar on the application
transaction.savepoint()
# Initialize the "application"
try:
TestAppInitializer(
app, self.products, self.packages, self.users).initialize()
self._install_application(makerequest(
app, environ={'SERVER_NAME': 'localhost'}))
except Exception as error:
# There was an error during the application 'setUp'. Abort
# the transaction and continue, otherwise test in other
# layers might fail because of this failure.
transaction.abort()
raise error
else:
# Close
transaction.commit()
finally:
# In any case, close the connection and continue
connection.close()
noSecurityManager()
示例12: removeOldUIDs
def removeOldUIDs(portal, out):
# remove temporary needed index
uc = getToolByName(portal, UID_CATALOG)
print >>out, 'Removing old uids\n'
if olduididx in uc.indexes():
uc.delIndex(olduididx)
if olduididx in uc.schema():
uc.delColumn(olduididx)
count = 0
allbrains = uc()
for brain in allbrains:
# Get a uid for each thingie
obj = brain.getObject()
objUID = getattr(aq_base(obj), olduididx, None)
if objUID is None:
continue # not an old style AT
delattr(obj, olduididx)
obj._updateCatalog(portal)
count += 1
if not count % 10:
print >>out, '.',
# avoid eating up all RAM
if not count % 250:
print >>out, '*',
transaction.savepoint(optimistic=True)
if USE_FULL_TRANSACTIONS:
transaction.commit()
else:
transaction.savepoint(optimistic=True)
print >>out, "\n%s old UID attributes removed." % count
print >>out, 'Done\n'
示例13: renameAfterCreation
def renameAfterCreation(obj):
# Can't rename without a subtransaction commit when using portal_factory
transaction.savepoint(optimistic=True)
# The id returned should be normalized already
new_id = generateUniqueId(obj)
obj.aq_inner.aq_parent.manage_renameObject(obj.id, new_id)
return new_id
示例14: test_move_comments_when_content_object_is_moved
def test_move_comments_when_content_object_is_moved(self):
# Create two folders and a content object with a comment
self.portal.invokeFactory(id="folder1", title="Folder 1", type_name="Folder")
self.portal.invokeFactory(id="folder2", title="Folder 2", type_name="Folder")
self.portal.folder1.invokeFactory(id="moveme", title="Move Me", type_name="Document")
conversation = IConversation(self.portal.folder1.moveme)
comment = createObject("plone.Comment")
comment_id = conversation.addComment(comment)
# We need to commit here so that _p_jar isn't None and move will work
transaction.savepoint(optimistic=True)
# Move moveme from folder1 to folder2
cp = self.portal.folder1.manage_cutObjects(ids=("moveme",))
self.portal.folder2.manage_pasteObjects(cp)
# Make sure no old comment brains are
brains = self.catalog.searchResults(
dict(portal_type="Discussion Item", path={"query": "/".join(self.portal.folder1.getPhysicalPath())})
)
self.assertEquals(len(brains), 0)
brains = self.catalog.searchResults(
dict(portal_type="Discussion Item", path={"query": "/".join(self.portal.folder2.getPhysicalPath())})
)
self.assertEquals(len(brains), 1)
self.assertEquals(brains[0].getPath(), "/plone/folder2/moveme/++conversation++default/" + str(comment_id))
示例15: testFileRenameKeepsMimeType
def testFileRenameKeepsMimeType(self):
self.assertEqual(self.folder.file.Format(), "application/pdf")
self.assertEqual(self.folder.file.getFile().content_type, "application/pdf")
transaction.savepoint(optimistic=True) # make rename work
self.folder.file.file_edit(id="foo")
self.assertEqual(self.folder.foo.Format(), "application/pdf")
self.assertEqual(self.folder.foo.getFile().content_type, "application/pdf")