本文整理汇总了Python中OFS.Image.manage_addFile函数的典型用法代码示例。如果您正苦于以下问题:Python manage_addFile函数的具体用法?Python manage_addFile怎么用?Python manage_addFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了manage_addFile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: installUi
def installUi(self):
'''Installs the user interface.'''
# Some useful imports
from OFS.Folder import manage_addFolder
from OFS.Image import manage_addImage, manage_addFile
from Products.PythonScripts.PythonScript import PythonScript
from Products.PageTemplates.ZopePageTemplate import \
manage_addPageTemplate
# Delete the existing folder if it existed.
zopeContent = self.app.objectIds()
if 'ui' in zopeContent: self.app.manage_delObjects(['ui'])
manage_addFolder(self.app, 'ui')
# Browse the physical ui folders (the Appy one and an app-specific, if
# the app defines one) and create the corresponding objects in the Zope
# folder. In the case of files having the same name in both folders,
# the one from the app-specific folder is chosen.
j = os.path.join
uiFolders = [j(j(appy.getPath(), 'gen'), 'ui')]
appUi = j(self.config.diskFolder, 'ui')
if os.path.exists(appUi): uiFolders.insert(0, appUi)
for ui in uiFolders:
for root, dirs, files in os.walk(ui):
folderName = root[len(ui):]
# Get the Zope folder that corresponds to this name
zopeFolder = self.app.ui
if folderName:
for name in folderName.strip(os.sep).split(os.sep):
zopeFolder = zopeFolder._getOb(name)
# Create sub-folders at this level
for name in dirs:
if not hasattr(zopeFolder.aq_base, name):
manage_addFolder(zopeFolder, name)
# Create files at this level
for name in files:
zopeName, ext = os.path.splitext(name)
if ext not in ('.pt', '.py'):
# In the ZODB, pages and scripts have their name without
# their extension.
zopeName = name
if hasattr(zopeFolder.aq_base, zopeName): continue
f = file(j(root, name))
if ext in gen.File.imageExts:
manage_addImage(zopeFolder, zopeName, f)
elif ext == '.pt':
manage_addPageTemplate(zopeFolder,zopeName,'',f.read())
elif ext == '.py':
obj = PythonScript(zopeName)
zopeFolder._setObject(zopeName, obj)
zopeFolder._getOb(zopeName).write(f.read())
else:
manage_addFile(zopeFolder, zopeName, f)
f.close()
# Update the home page
if 'index_html' in zopeContent:
self.app.manage_delObjects(['index_html'])
manage_addPageTemplate(self.app, 'index_html', '', homePage)
# Update the error page
if 'standard_error_message' in zopeContent:
self.app.manage_delObjects(['standard_error_message'])
manage_addPageTemplate(self.app, 'standard_error_message', '',errorPage)
开发者ID:a-iv,项目名称:appy,代码行数:60,代码来源:installer.py
示例2: testPasteMultiSameID
def testPasteMultiSameID(self):
self.assertTrue('file' in self.folder1.objectIds())
self.assertFalse('file1' in self.folder1.objectIds())
manage_addFile(self.folder1, 'file1',
file=b'', content_type='text/plain')
self.assertFalse('file2' in self.folder1.objectIds())
manage_addFile(self.folder1, 'file2',
file=b'', content_type='text/plain')
self.assertFalse('file' in self.folder2.objectIds())
manage_addFile(self.folder2, 'file',
file=b'', content_type='text/plain')
self.assertFalse('file1' in self.folder2.objectIds())
manage_addFile(self.folder2, 'file1',
file=b'', content_type='text/plain')
self.assertFalse('file2' in self.folder2.objectIds())
manage_addFile(self.folder2, 'file2',
file=b'', content_type='text/plain')
cookie = self.folder1.manage_copyObjects(
ids=('file', 'file1', 'file2',))
result = self.folder2.manage_pasteObjects(cookie)
self.assertTrue('file' in self.folder1.objectIds())
self.assertTrue('file1' in self.folder1.objectIds())
self.assertTrue('file2' in self.folder1.objectIds())
self.assertTrue('file' in self.folder2.objectIds())
self.assertTrue('file1' in self.folder2.objectIds())
self.assertTrue('file2' in self.folder2.objectIds())
self.assertTrue('copy_of_file' in self.folder2.objectIds())
self.assertTrue('copy_of_file1' in self.folder2.objectIds())
self.assertTrue('copy_of_file2' in self.folder2.objectIds())
self.assertEqual(result, [
{'id': 'file', 'new_id': 'copy_of_file'},
{'id': 'file1', 'new_id': 'copy_of_file1'},
{'id': 'file2', 'new_id': 'copy_of_file2'},
])
开发者ID:dhavlik,项目名称:Zope,代码行数:34,代码来源:testCopySupport.py
示例3: testPasteMultiSameID
def testPasteMultiSameID( self ):
self.failUnless( 'file' in self.folder1.objectIds() )
self.failIf( 'file1' in self.folder1.objectIds() )
manage_addFile(self.folder1, 'file1',
file='', content_type='text/plain')
self.failIf( 'file2' in self.folder1.objectIds() )
manage_addFile(self.folder1, 'file2',
file='', content_type='text/plain')
self.failIf( 'file' in self.folder2.objectIds() )
manage_addFile(self.folder2, 'file',
file='', content_type='text/plain')
self.failIf( 'file1' in self.folder2.objectIds() )
manage_addFile(self.folder2, 'file1',
file='', content_type='text/plain')
self.failIf( 'file2' in self.folder2.objectIds() )
manage_addFile(self.folder2, 'file2',
file='', content_type='text/plain')
cookie = self.folder1.manage_copyObjects( ids=('file','file1','file2',) )
result = self.folder2.manage_pasteObjects( cookie )
self.failUnless( 'file' in self.folder1.objectIds() )
self.failUnless( 'file1' in self.folder1.objectIds() )
self.failUnless( 'file2' in self.folder1.objectIds() )
self.failUnless( 'file' in self.folder2.objectIds() )
self.failUnless( 'file1' in self.folder2.objectIds() )
self.failUnless( 'file2' in self.folder2.objectIds() )
self.failUnless( 'copy_of_file' in self.folder2.objectIds() )
self.failUnless( 'copy_of_file1' in self.folder2.objectIds() )
self.failUnless( 'copy_of_file2' in self.folder2.objectIds() )
self.failUnless( result == [{'id':'file', 'new_id':'copy_of_file'},
{'id':'file1', 'new_id':'copy_of_file1'},
{'id':'file2', 'new_id':'copy_of_file2'}])
开发者ID:wpjunior,项目名称:proled,代码行数:31,代码来源:testCopySupport.py
示例4: _initFolders
def _initFolders(self):
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 )
manage_addFolder( self.app, 'folder1' )
manage_addFolder( self.app, '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.commit()
except:
self.connection.close()
raise
transaction.begin()
return self.app._getOb( 'folder1' ), self.app._getOb( 'folder2' )
开发者ID:wpjunior,项目名称:proled,代码行数:28,代码来源:testCopySupport.py
示例5: setUp
def setUp(self):
self.responseOut = cStringIO.StringIO()
self.connection = makeConnection()
try:
r = self.connection.root()
a = Application()
r['Application'] = a
self.root = a
self.app = makerequest(self.root, stdout=self.responseOut)
try: self.app._delObject(TESTFOLDER_NAME)
except AttributeError: pass
manage_addFolder(self.app, TESTFOLDER_NAME)
folder = getattr( self.app, TESTFOLDER_NAME )
data = string.letters
manage_addFile( folder, 'file'
, file=data, content_type='text/plain')
self.file = folder.file
self.data = data
# 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.commit()
except:
self.connection.close()
raise
开发者ID:wpjunior,项目名称:proled,代码行数:28,代码来源:testRanges.py
示例6: test_copy_cant_copy_invisible_items
def test_copy_cant_copy_invisible_items(self):
# User can view folder1.
# User cannot view private file in folder1.
# When user copies folder1, the private file should not be copied,
# because the user would get the Owner role on the copy,
# and be able to view it anyway.
from AccessControl.Permissions import add_folders
from AccessControl.Permissions import view
folder1, folder2 = self._initFolders()
manage_addFile(folder1, 'private',
file=b'', content_type='text/plain')
manage_addFile(folder1, 'public',
file=b'', content_type='text/plain')
folder1.private.manage_permission(view, roles=(), acquire=0)
folder2.manage_permission(add_folders, roles=('Anonymous',), acquire=1)
copy_info = folder2.manage_pasteObjects(
self.app.manage_copyObjects('folder1')
)
new_id = copy_info[0]['new_id']
new_folder = folder2[new_id]
# The private item should not be in the copy.
self.assertTrue('private' not in new_folder.objectIds())
# There is nothing wrong with copying the public item.
self.assertTrue('public' in new_folder.objectIds())
开发者ID:dhavlik,项目名称:Zope,代码行数:27,代码来源:testCopySupport.py
示例7: test_file_preserves_content_type
def test_file_preserves_content_type(self):
# Verify that a file's content_type is preserved.
# Note that there is some contention between content_type
# guessing and the content_type property.
data = (
'\n'
'This is not just text\n'
'In a frivolous file test\n'
'But a wise practice.\n'
)
ct = 'text/x-haiku'
conn = self.db.open()
try:
app = conn.root()['Application']
manage_addFile(app, 'file', StringIO(data))
app.file.content_type = ct
transaction.commit()
conn2 = self.db.open()
try:
app = conn2.root()['Application']
self.assertEqual(app.file.content_type, ct)
finally:
conn2.close()
finally:
conn.close()
开发者ID:goschtl,项目名称:zope,代码行数:26,代码来源:zope2testbase.py
示例8: _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' )
开发者ID:goschtl,项目名称:zope,代码行数:28,代码来源:test_PortalFolder.py
示例9: installUi
def installUi(self):
'''Installs the user interface'''
# Some useful imports
from OFS.Folder import manage_addFolder
from OFS.Image import manage_addImage, manage_addFile
# Delete the existing folder if it existed
zopeContent = self.app.objectIds()
for name in ('ui', self.favIcon):
if name in zopeContent: self.app.manage_delObjects([name])
manage_addFolder(self.app, 'ui')
# Browse the physical ui folders (the Appy one and an app-specific, if
# the app defines one) and create the corresponding objects in the Zope
# folder. In the case of files having the same name in both folders,
# the one from the app-specific folder is chosen.
j = os.path.join
uiFolders = [j(j(appy.getPath(), 'gen'), 'ui')]
for uiFolder in self.config.appConfig.uiFolders:
if uiFolder.startswith('..'):
folder = j(os.path.dirname(self.config.diskFolder),uiFolder[3:])
else:
folder = j(self.config.diskFolder, uiFolder)
if os.path.exists(folder):
uiFolders.insert(0, folder)
for ui in uiFolders:
for root, dirs, files in os.walk(ui):
folderName = root[len(ui):]
# Get the Zope folder that corresponds to this name
zopeFolder = self.app.ui
if folderName:
for name in folderName.strip(os.sep).split(os.sep):
zopeFolder = zopeFolder._getOb(name)
# Create sub-folders at this level
for name in dirs:
if not hasattr(zopeFolder.aq_base, name):
manage_addFolder(zopeFolder, name)
# Create files at this level
for name in files:
ext = os.path.splitext(name)[1]
if hasattr(zopeFolder.aq_base, name): continue
f = file(j(root, name))
if name == self.favIcon:
if not hasattr(self.app, name):
# Copy it at the root. Else, IE won't notice it.
manage_addImage(self.app, name, f)
elif ext in gen.File.imageExts:
manage_addImage(zopeFolder, name, f)
else:
manage_addFile(zopeFolder, name, f)
f.close()
# Update home and error pages
from Products.PageTemplates.ZopePageTemplate import \
manage_addPageTemplate
if 'index_html' in zopeContent:
self.app.manage_delObjects(['index_html'])
manage_addPageTemplate(self.app, 'index_html', '', homePage)
if 'standard_error_message' in zopeContent:
self.app.manage_delObjects(['standard_error_message'])
manage_addPageTemplate(self.app, 'standard_error_message', '',
errorPage)
开发者ID:tonibagur,项目名称:appy,代码行数:59,代码来源:installer.py
示例10: testPasteSpecialName
def testPasteSpecialName(self):
manage_addFile(self.folder1, 'copy_of_',
file='', content_type='text/plain')
cookie = self.folder1.manage_copyObjects(ids=('copy_of_',))
result = self.folder1.manage_pasteObjects(cookie)
self.assertEqual(self.folder1.objectIds(),
['file', 'copy_of_', 'copy2_of_'])
self.assertEqual(result, [{'id':'copy_of_', 'new_id':'copy2_of_'}])
开发者ID:wpjunior,项目名称:proled,代码行数:8,代码来源:testCopySupport.py
示例11: testCopyNewObject
def testCopyNewObject(self):
self.failIf('newfile' in self.folder1.objectIds())
manage_addFile(self.folder1, 'newfile',
file='', content_type='text/plain')
cookie = self.folder1.manage_copyObjects(ids=('newfile',))
self.folder2.manage_pasteObjects(cookie)
self.failUnless('newfile' in self.folder1.objectIds())
self.failUnless('newfile' in self.folder2.objectIds())
开发者ID:wpjunior,项目名称:proled,代码行数:8,代码来源:testCopySupport.py
示例12: test_can_handle_non_ascii_URLs
def test_can_handle_non_ascii_URLs(self):
from OFS.Image import manage_addFile
manage_addFile(self.app, 'täst', u'çöńtêñt'.encode('utf-8'))
browser = Testing.testbrowser.Browser()
browser.login('manager', 'manager_pass')
browser.open('http://localhost/{}'.format(quote('täst')))
self.assertEqual(browser.contents.decode('utf-8'), u'çöńtêñt')
开发者ID:zopefoundation,项目名称:Zope,代码行数:9,代码来源:test_WSGIPublisher.py
示例13: process_file_upload
def process_file_upload(self, file='', REQUEST=None):
"""
Handles the upload of a new file.
@param file: uploaded file
@param REQUEST: I{optional} parameter to do the redirect
"""
if file != '':
if hasattr(file, 'filename'):
if file.filename != '':
manage_addFile(self, '', file)
if REQUEST: REQUEST.RESPONSE.redirect('%s/toolbox_html' % self.absolute_url())
开发者ID:eaudeweb,项目名称:naaya,代码行数:11,代码来源:NyEpozToolbox.py
示例14: testPasteSingleSameID
def testPasteSingleSameID( self ):
self.assertTrue( 'file' in self.folder1.objectIds() )
self.assertFalse( 'file' in self.folder2.objectIds() )
manage_addFile(self.folder2, 'file',
file='', content_type='text/plain')
cookie = self.folder1.manage_copyObjects( ids=('file',) )
result = self.folder2.manage_pasteObjects( cookie )
self.assertTrue( 'file' in self.folder1.objectIds() )
self.assertTrue( 'file' in self.folder2.objectIds() )
self.assertTrue( 'copy_of_file' in self.folder2.objectIds() )
self.assertTrue( result == [{'id':'file', 'new_id':'copy_of_file'}])
开发者ID:Andyvs,项目名称:TrackMonthlyExpenses,代码行数:11,代码来源:testCopySupport.py
示例15: _initFolders
def _initFolders(self):
from ..PortalFolder import PortalFolder
self.app._setObject('folder1', PortalFolder('folder1'))
self.app._setObject('folder2', PortalFolder('folder2'))
folder1 = getattr(self.app, 'folder1')
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)
return self.app._getOb('folder1'), self.app._getOb('folder2')
开发者ID:zopefoundation,项目名称:Products.CMFCore,代码行数:13,代码来源:test_PortalFolder.py
示例16: setUp
def setUp( self ):
import cStringIO
import transaction
from AccessControl import SecurityManager
from AccessControl.SecurityManagement import newSecurityManager
from OFS.Application import Application
from OFS.Folder import manage_addFolder
from OFS.Image import manage_addFile
from Testing.makerequest import makerequest
from ZODB.DB import DB
from ZODB.DemoStorage import DemoStorage
s = DemoStorage()
self.connection = DB(s).open()
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 )
manage_addFolder( self.app, 'folder1' )
folder1 = getattr( self.app, 'folder1' )
setattr(folder1, '+something', 'plus')
folder1.all_meta_types = \
({ 'name' : 'File'
, 'action' : 'manage_addFile'
, 'permission' : 'Add images and files'
}
,
)
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.commit()
except:
self.connection.close()
raise
transaction.begin()
self.folder1 = getattr( self.app, 'folder1' )
self.policy = UnitTestSecurityPolicy()
self.oldPolicy = SecurityManager.setSecurityPolicy( self.policy )
newSecurityManager( None, self._makeUser().__of__( self.root ) )
开发者ID:Andyvs,项目名称:TrackMonthlyExpenses,代码行数:50,代码来源:testTraverse.py
示例17: test_large_file
def test_large_file(self):
# Verify that 256K file objects can be serialized/deserialized.
# Zope splits files larger than 64K into chunks.
data = 'data' * 65536
conn = self.db.open()
try:
app = conn.root()['Application']
manage_addFile(app, 'file', StringIO(data))
transaction.commit()
self.assertEqual(str(app.file), data)
conn2 = self.db.open()
try:
app = conn2.root()['Application']
self.assertEqual(str(app.file), data)
transaction.abort()
finally:
conn2.close()
finally:
conn.close()
开发者ID:goschtl,项目名称:zope,代码行数:20,代码来源:zope2testbase.py
示例18: setUp
def setUp( self ):
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 )
manage_addFolder( self.app, 'folder1' )
folder1 = getattr( self.app, 'folder1' )
folder1.all_meta_types = \
( { 'name' : 'File'
, 'action' : 'manage_addFile'
, 'permission' : 'Add images and files'
}
,
)
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.
get_transaction().commit()
except:
self.connection.close()
raise
get_transaction().begin()
self.folder1 = getattr( self.app, 'folder1' )
self.policy = UnitTestSecurityPolicy()
self.oldPolicy = SecurityManager.setSecurityPolicy( self.policy )
newSecurityManager( None, UnitTestUser().__of__( self.root ) )
开发者ID:OS2World,项目名称:APP-SERVER-Zope,代码行数:37,代码来源:testTraverse.py
示例19: setUp
def setUp(self):
import io
import string
import transaction
from OFS.Application import Application
from OFS.Folder import manage_addFolder
from OFS.Image import manage_addFile
from Testing.makerequest import makerequest
self.responseOut = io.BytesIO()
self.connection = makeConnection()
try:
r = self.connection.root()
a = Application()
r['Application'] = a
self.root = a
self.app = makerequest(self.root, stdout=self.responseOut)
try:
self.app._delObject(TESTFOLDER_NAME)
except AttributeError:
pass
manage_addFolder(self.app, TESTFOLDER_NAME)
folder = getattr(self.app, TESTFOLDER_NAME)
data = string.ascii_letters.encode('ascii')
manage_addFile(
folder, 'file', file=data, content_type='text/plain')
self.file = folder.file
self.data = data
# 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.commit()
except Exception:
self.connection.close()
raise
开发者ID:zopefoundation,项目名称:Zope,代码行数:37,代码来源:testRanges.py
示例20: test_corrected_file_extension
def test_corrected_file_extension(self):
# Verify that certain content_types use the correct filename
# extension.
data = 'Hello, world!'
conn = self.db.open()
try:
app = conn.root()['Application']
manage_addFile(app, 'hello', StringIO(data),
content_type='text/plain')
manage_addFile(app, 'world.dat', StringIO(data),
content_type='text/plain')
manage_addFile(app, 'binary_file', StringIO(data),
content_type='application/octet-stream')
transaction.commit()
dir = self.conn.basepath
names = os.listdir(dir)
self.assert_(('hello.txt') in names, names)
self.assert_(('world.dat') in names, names)
self.assert_(('hello') not in names, names)
self.assert_(('binary_file') in names, names)
finally:
conn.close()
开发者ID:goschtl,项目名称:zope,代码行数:23,代码来源:testzope2fs.py
注:本文中的OFS.Image.manage_addFile函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论