def test_OFS_ObjectManager__importObjectFromFile_xml(self):
        from OFS.DTMLMethod import DTMLMethod
        from OFS.Folder import Folder
        from OFS.XMLExportImport import exportXML

        connection, app = self._makeJarAndRoot()
        dm = DTMLMethod('test')
        dm._setId('test')
        dm.munge(_LONG_DTML)
        app._setObject('test', dm)
        sub = Folder('sub')
        app._setObject('sub', sub)
        transaction.savepoint(optimistic=True) # need an OID!
        oid = dm._p_oid
        sub = app._getOb('sub')

        handle, path = tempfile.mkstemp(suffix='.xml')
        try:
            ostream = os.fdopen(handle,'wb')
            data = exportXML(connection, oid, ostream)
            ostream.close()
            sub._importObjectFromFile(path, 0, 0)
        finally:
            # if this operaiton fails with a 'Permission Denied' error,
            # then comment it out as it's probably masking a failure in
            # the block above.
            os.remove(path)
Пример #2
0
    def test_export_import_as_file_idempotent(self):
        from OFS.DTMLMethod import DTMLMethod
        from OFS.XMLExportImport import exportXML
        from OFS.XMLExportImport import importXML

        connection, app = self._makeJarAndRoot()
        dm = DTMLMethod('test')
        dm.munge(_LONG_DTML)
        app._setObject('test', dm)
        transaction.savepoint(optimistic=True) # need an OID!
        oid = dm._p_oid

        handle, path = tempfile.mkstemp(suffix='.xml')
        try:
            ostream = os.fdopen(handle,'wb')
            data = exportXML(connection, oid, ostream)
            ostream.close()
            newobj = importXML(connection, path)
            self.assertTrue(isinstance(newobj, DTMLMethod))
            self.assertEqual(newobj.read(), dm.read())
        finally:
            # if this operaiton fails with a 'Permission Denied' error,
            # then comment it out as it's probably masking a failure in
            # the block above.
            os.remove(path)
    def test_export_import_as_file_idempotent(self):
        from OFS.DTMLMethod import DTMLMethod
        from OFS.XMLExportImport import exportXML
        from OFS.XMLExportImport import importXML

        connection, app = self._makeJarAndRoot()
        dm = DTMLMethod('test')
        dm.munge(_LONG_DTML)
        app._setObject('test', dm)
        transaction.savepoint(optimistic=True) # need an OID!
        oid = dm._p_oid

        handle, path = tempfile.mkstemp(suffix='.xml')
        try:
            ostream = os.fdopen(handle,'wb')
            data = exportXML(connection, oid, ostream)
            ostream.close()
            newobj = importXML(connection, path)
            self.assertTrue(isinstance(newobj, DTMLMethod))
            self.assertEqual(newobj.read(), dm.read())
        finally:
            # if this operaiton fails with a 'Permission Denied' error,
            # then comment it out as it's probably masking a failure in
            # the block above.
            os.remove(path)
Пример #4
0
def addDTMLMethod(self, id, title='', file=''):
    id = str(id)
    title = str(title)
    ob = DTMLMethod(source_string=file, __name__=id)
    ob.title = title
    username = getSecurityManager().getUser().getUserName()
    ob.manage_addLocalRoles(username, ['Owner'])
    #ob.setSubOwner('both') #?
    self._setObject(id, ob)
Пример #5
0
def addDTMLMethod(self, id, title='', file=''):
    id=str(id)
    title=str(title)
    ob = DTMLMethod(source_string=file, __name__=id)
    ob.title = title
    username = getSecurityManager().getUser().getUserName()
    ob.manage_addLocalRoles(username, ['Owner'])
    #ob.setSubOwner('both') #?
    self._setObject(id, ob)
Пример #6
0
 def __call__(self, value, *args, **kwargs):
     if not isinstance(value, DTMLMethod):
         dtml = DTMLMethod('no_id')
         dtml.raw = value
         value = dtml
     try:
         value.parse(value.read())
     except ParseError, e:
         return e
Пример #7
0
	def __init__(self, authId, propId, memberId, groupId, cryptoId,
				 cookie_mode=0, session_length=0, sessionTracking=None,
				 idleTimeout=0, not_session_length=0):
		self.cookie_mode=cookie_mode
		self.sessionLength=session_length
		self.notSessionLength=not_session_length
		self.sessionTracking=sessionTracking
		self.idleTimeout=idleTimeout
		
		_docLogin=DTMLFile('dtml/docLogin',globals())
		_docLogout=DTMLFile('dtml/docLogout',globals())

		docLogin=DTMLMethod(__name__='docLogin')
		docLogin.manage_edit(data=_docLogin, title='Login Page')
		self._setObject('docLogin', docLogin, None, None, 0)

		docLogout=DTMLMethod(__name__='docLogout')
		docLogout.manage_edit(data=_docLogout, title='Logout Page')
		self._setObject('docLogout', docLogout, None, None, 0)

		postUserCreate=DTMLMethod(__name__='postUserCreate')
		postUserCreate.manage_edit(data=_postUserCreate, title='Post User Creation methods')
		self._setObject('postUserCreate', postUserCreate, None, None, 0)

		self.manage_addAuthSource=self.authSources[authId].manage_addMethod
		self.manage_addPropSource=self.propSources[propId].manage_addMethod
		self.manage_addMembershipSource=self.membershipSources[memberId].manage_addMethod

		self.manage_addGroupSource=None # UNUSED by ScoDoc
		self.currentGroupsSource=None

		if cryptoId:
			self.cryptoId = cryptoId
		else:
			self.cryptoId = 'Crypt'
	def _customizeTemplate(self,name):
		message=""
		if not(name in self.objectIds()): # if no scriptname script in current form manager
			defaultTemplate = getattr(self,name) # gets the first script acquired
			defaultBody = defaultTemplate.document_src()
			template = DTMLMethod(name)
			template.manage_edit(data=defaultBody,title=name)
			self._setObject(name,template)
			message+="portal_status_message=custom "+name+" has been added"
			
		return message
Пример #9
0
    def PUT_factory( self, name, typ, body ):
        """
            Dispatcher for PUT requests to non-existent IDs.  Returns
            an object of the appropriate type (or None, if we don't
            know what to do).
        """
        major, minor = typ.split('/', 1)

        if major == 'image':
            return Image( id=name
                        , title=''
                        , file=''
                        , content_type=typ
                        )

        if major == 'text':

            if minor == 'x-python':
                return PythonScript( id=name )

            if minor in ('html', 'xml'):
                return ZopePageTemplate( name )

            return DTMLMethod( __name__=name )

        return None
Пример #10
0
def _initDCWorkflowScripts(workflow, scripts, context):
    """ Initialize DCWorkflow scripts
    """
    for s_info in scripts:

        id = str(s_info['script_id'])  # no unicode!
        meta_type = s_info['meta_type']
        filename = s_info['filename']
        file = ''

        if filename:
            file = context.readDataFile(filename)

        if meta_type == PythonScript.meta_type:
            script = PythonScript(id)
            script.write(file)

        elif meta_type == ExternalMethod.meta_type:
            script = ExternalMethod(id, '', s_info['module'],
                                    s_info['function'])

        elif meta_type == DTMLMethod.meta_type:
            script = DTMLMethod(file, __name__=id)

        workflow.scripts._setObject(id, script)
Пример #11
0
    def test_export_import_as_string_idempotent(self):
        from OFS.DTMLMethod import DTMLMethod
        from OFS.XMLExportImport import exportXML
        from OFS.XMLExportImport import importXML

        connection, app = self._makeJarAndRoot()
        dm = DTMLMethod('test')
        dm.munge(_LONG_DTML)
        app._setObject('test', dm)
        transaction.savepoint(optimistic=True) # need an OID!
        oid = dm._p_oid

        stream = StringIO()

        data = exportXML(connection, oid, stream)
        stream.seek(0)

        newobj = importXML(connection, stream)
        self.assertTrue(isinstance(newobj, DTMLMethod))
        self.assertEqual(newobj.read(), dm.read())
    def test_export_import_as_string_idempotent(self):
        from OFS.DTMLMethod import DTMLMethod
        from OFS.XMLExportImport import exportXML
        from OFS.XMLExportImport import importXML

        connection, app = self._makeJarAndRoot()
        dm = DTMLMethod('test')
        dm.munge(_LONG_DTML)
        app._setObject('test', dm)
        transaction.savepoint(optimistic=True) # need an OID!
        oid = dm._p_oid

        stream = StringIO()

        data = exportXML(connection, oid, stream)
        stream.seek(0)

        newobj = importXML(connection, stream)
        self.assertTrue(isinstance(newobj, DTMLMethod))
        self.assertEqual(newobj.read(), dm.read())
Пример #13
0
 def PUT_factory(self, name, typ, body):
     """
         Hook PUT creation to make objects of the right type when
         new item uploaded via FTP/WebDAV.
     """
     if typ is None:
         typ, enc = guess_content_type()
     if typ == 'text/x-python':
         return PythonScript(name)
     if typ[:4] == 'text':
         return DTMLMethod('', __name__=name)
     return None  # take the default, then
Пример #14
0
    def test_OFS_ObjectManager__importObjectFromFile_xml(self):
        from OFS.DTMLMethod import DTMLMethod
        from OFS.Folder import Folder
        from OFS.XMLExportImport import exportXML

        connection, app = self._makeJarAndRoot()
        dm = DTMLMethod('test')
        dm._setId('test')
        dm.munge(_LONG_DTML)
        app._setObject('test', dm)
        sub = Folder('sub')
        app._setObject('sub', sub)
        transaction.savepoint(optimistic=True) # need an OID!
        oid = dm._p_oid
        sub = app._getOb('sub')

        handle, path = tempfile.mkstemp(suffix='.xml')
        try:
            ostream = os.fdopen(handle,'wb')
            data = exportXML(connection, oid, ostream)
            ostream.close()
            sub._importObjectFromFile(path, 0, 0)
        finally:
            # if this operaiton fails with a 'Permission Denied' error,
            # then comment it out as it's probably masking a failure in
            # the block above.
            os.remove(path)
Пример #15
0
def _populate(app):
    from OFS.DTMLMethod import DTMLMethod
    from Products.Sessions.BrowserIdManager import BrowserIdManager
    from Products.Sessions.SessionDataManager import SessionDataManager
    from Products.TemporaryFolder.TemporaryFolder import MountedTemporaryFolder
    from Products.Transience.Transience import TransientObjectContainer
    import transaction
    bidmgr = BrowserIdManager(idmgr_name)
    tf = MountedTemporaryFolder(tf_name, title="Temporary Folder")
    toc = TransientObjectContainer(toc_name,
                                   title='Temporary '
                                   'Transient Object Container',
                                   timeout_mins=20)
    session_data_manager = SessionDataManager(id=sdm_name,
                                              path='/' + tf_name + '/' +
                                              toc_name,
                                              title='Session Data Manager',
                                              requestName='TESTOFSESSION')

    try:
        app._delObject(idmgr_name)
    except (AttributeError, KeyError):
        pass

    try:
        app._delObject(tf_name)
    except (AttributeError, KeyError):
        pass

    try:
        app._delObject(sdm_name)
    except (AttributeError, KeyError):
        pass

    try:
        app._delObject('index_html')
    except (AttributeError, KeyError):
        pass

    app._setObject(idmgr_name, bidmgr)

    app._setObject(sdm_name, session_data_manager)

    app._setObject(tf_name, tf)
    transaction.commit()

    app.temp_folder._setObject(toc_name, toc)
    transaction.commit()

    # index_html necessary for publishing emulation for testAutoReqPopulate
    app._setObject('index_html', DTMLMethod('', __name__='foo'))
    transaction.commit()
Пример #16
0
 def manage_doCustomize(self, folder_path, data=None, RESPONSE=None):
     '''
     Makes a DTMLMethod with the same code.
     '''
     custFolder = self.getCustomizableObject()
     fpath = tuple(split(folder_path, '/'))
     folder = self.restrictedTraverse(fpath)
     if data is None:
         data = self.read()
     id = self.getId()
     obj = DTMLMethod(data, __name__=id)
     folder._verifyObjectPaste(obj, validate_src=0)
     folder._setObject(id, obj)
     if RESPONSE is not None:
         RESPONSE.redirect('%s/%s/manage_main' %
                           (folder.absolute_url(), id))
Пример #17
0
    def test_managersExist(self):
        from OFS.Cache import managersExist
        from OFS.DTMLMethod import DTMLMethod
        root = Folder('root')
        root._setObject('root_cache', DummyCacheManager('root_cache'))
        root._setObject('child', Folder('child'))
        root.child._setObject('child_cache', DummyCacheManager('child_cache'))
        root.child._setObject('child_content', DTMLMethod('child_content'))

        # To begin with, cache managers will be found correctly
        # using managersExist
        self.assertTrue(managersExist(root.child.child_content))

        # Now we delete the cache in the child folder
        root.child.manage_delObjects(['child_cache'])

        # The parent_cache should still trigger managersExist
        self.assertTrue(managersExist(root.child.child_content))
Пример #18
0
def _initDCWorkflowScripts( workflow, scripts, context ):

    """ Initialize DCWorkflow scripts
    """
    for s_info in scripts:

        id = str( s_info[ 'script_id' ] ) # no unicode!
        meta_type = s_info[ 'meta_type' ]
        filename = s_info[ 'filename' ]
        file = ''

        if filename:
            file = context.readDataFile( filename )

        if meta_type == PythonScript.meta_type:
            script = PythonScript( id )
            script.write( file )

        elif meta_type == ExternalMethod.meta_type:
            script = ExternalMethod( id
                                   , ''
                                   , s_info['module']
                                   , s_info['function']
                                   )

        elif meta_type == DTMLMethod.meta_type:
            script = DTMLMethod( file, __name__=id )

        else:
            for mt in workflow.scripts.filtered_meta_types():
                if mt['name']==meta_type:
                    if hasattr(mt['instance'], 'write'):
                        script = mt['instance'](id)
                        script.write(file)
                    else:
                        script = mt['instance'](file, __name__=id)
                    break
            else:
                raise ValueError, 'Invalid type: %s' % meta_type

        if workflow.scripts.has_key(id):
            workflow.scripts._delObject(id)
        workflow.scripts._setObject( id, script )
Пример #19
0
    def test_dtml_method(self):
        conn = self.db.open()
        try:
            app = conn.root()['Application']
            m = DTMLMethod()
            m._setId('m')
            method_body = '''All <dtml-var expr="'OK'">.'''
            m.manage_edit(method_body, 'test method')
            app._setObject(m.getId(), m, set_owner=0)
            transaction.commit()

            conn2 = self.db.open()
            try:
                app = conn2.root()['Application']
                m = app.m
                self.assertEqual(m.title, 'test method')
                res = m()
                self.assertEqual(res, 'All OK.')
            finally:
                conn2.close()

        finally:
            conn.close()
Пример #20
0
    def test_dtml_method(self):
        conn = self.db.open()
        try:
            app = conn.root()['Application']
            m = DTMLMethod()
            m._setId('m')
            method_body = '''All <dtml-var expr="'OK'">.'''
            m.manage_edit(method_body, 'test method')
            app._setObject(m.getId(), m, set_owner=0)
            transaction.commit()

            conn2 = self.db.open()
            try:
                app = conn2.root()['Application']
                m = app.m
                self.assertEqual(m.title, 'test method')
                res = m()
                self.assertEqual(res, 'All OK.')
            finally:
                conn2.close()

        finally:
            conn.close()
Пример #21
0
 def set(self, instance, value, **kwargs):
     if not isinstance(value, DTMLMethod):
         dtml = DTMLMethod(self.getName())
         dtml.munge(value)
         value = dtml
     ObjectField.set(self, instance, value, **kwargs)
Пример #22
0
    def _makeSite(self):
        import base64
        from cStringIO import StringIO
        import urllib

        from AccessControl.User import UserFolder
        from OFS.Folder import Folder
        from OFS.DTMLMethod import DTMLMethod

        root = Folder()
        root.isTopLevelPrincipiaApplicationObject = 1  # User folder needs this
        root.getPhysicalPath = lambda: ()  # hack
        root._View_Permission = ('Anonymous',)

        users = UserFolder()
        users._setId('acl_users')
        users._doAddUser('abraham', 'pass-w', ('Patriarch',), ())
        users._doAddUser('isaac', 'pass-w', ('Son',), ())
        root._setObject(users.id, users)

        cc = self._makeOne()
        cc.id = self._CC_ID
        root._setObject(cc.id, cc)

        index = DTMLMethod()
        index.munge('This is the default view')
        index._setId('index_html')
        root._setObject(index.getId(), index)

        login = DTMLMethod()
        login.munge('Please log in first.')
        login._setId('login_form')
        root._setObject(login.getId(), login)

        protected = DTMLMethod()
        protected._View_Permission = ('Manager',)
        protected.munge('This is the protected view')
        protected._setId('protected')
        root._setObject(protected.getId(), protected)

        req = makerequest(root, StringIO())
        self._finally = req.close

        credentials = urllib.quote(
            base64.encodestring('abraham:pass-w').rstrip())

        return root, cc, req, credentials
    def _makeSite(self):
        from OFS.DTMLMethod import DTMLMethod
        from OFS.Folder import Folder
        from OFS.userfolder import UserFolder

        class TestFolder(Folder):
            def getPhysicalPath(self):
                return ()

        root = TestFolder()
        root.isTopLevelPrincipiaApplicationObject = 1  # User folder needs this
        root._View_Permission = ('Anonymous',)

        users = UserFolder()
        users._setId('acl_users')
        users._doAddUser('abraham', 'pass-w', ('Patriarch',), ())
        users._doAddUser('isaac', 'pass-w', ('Son',), ())
        root._setObject(users.id, users)

        cc = self._makeOne()
        root._setObject(cc.id, cc)

        index = DTMLMethod()
        index.munge('This is the default view')
        index._setId('index_html')
        root._setObject(index.getId(), index)

        login = DTMLMethod()
        login.munge('Please log in first.')
        login._setId('login_form')
        root._setObject(login.getId(), login)

        protected = DTMLMethod()
        protected._View_Permission = ('Manager',)
        protected.munge('This is the protected view')
        protected._setId('protected')
        root._setObject(protected.getId(), protected)

        req = makerequest(root, StringIO())
        self._finally = req.close

        credentials = quote(base64_encode(b'abraham:pass-w'))

        return root, cc, req, credentials
Пример #24
0
 def getDefault(self, instance):
     value = ObjectField.getDefault(self, instance)
     dtml = DTMLMethod(self.getName())
     dtml.munge(value)
     return dtml.__of__(instance)
Пример #25
0
    def _makeSite(self):
        import base64
        from cStringIO import StringIO
        import urllib

        from AccessControl.User import UserFolder
        from OFS.Folder import Folder
        from OFS.DTMLMethod import DTMLMethod

        root = Folder()
        root.isTopLevelPrincipiaApplicationObject = 1  # User folder needs this
        root.getPhysicalPath = lambda: ()  # hack
        root._View_Permission = ('Anonymous', )

        users = UserFolder()
        users._setId('acl_users')
        users._doAddUser('abraham', 'pass-w', ('Patriarch', ), ())
        users._doAddUser('isaac', 'pass-w', ('Son', ), ())
        root._setObject(users.id, users)

        cc = self._makeOne()
        cc.id = self._CC_ID
        root._setObject(cc.id, cc)

        index = DTMLMethod()
        index.munge('This is the default view')
        index._setId('index_html')
        root._setObject(index.getId(), index)

        login = DTMLMethod()
        login.munge('Please log in first.')
        login._setId('login_form')
        root._setObject(login.getId(), login)

        protected = DTMLMethod()
        protected._View_Permission = ('Manager', )
        protected.munge('This is the protected view')
        protected._setId('protected')
        root._setObject(protected.getId(), protected)

        req = makerequest(root, StringIO())
        self._finally = req.close

        credentials = urllib.quote(
            base64.encodestring('abraham:pass-w').rstrip())

        return root, cc, req, credentials
Пример #26
0
    def _makeSite(self):
        from OFS.DTMLMethod import DTMLMethod
        from OFS.Folder import Folder
        from OFS.userfolder import UserFolder

        class TestFolder(Folder):
            def getPhysicalPath(self):
                return ()

        root = TestFolder()
        root.isTopLevelPrincipiaApplicationObject = 1  # User folder needs this
        root._View_Permission = ('Anonymous', )

        users = UserFolder()
        users._setId('acl_users')
        users._doAddUser('abraham', 'pass-w', ('Patriarch', ), ())
        users._doAddUser('isaac', 'pass-w', ('Son', ), ())
        root._setObject(users.id, users)

        cc = self._makeOne()
        root._setObject(cc.id, cc)

        index = DTMLMethod()
        index.munge('This is the default view')
        index._setId('index_html')
        root._setObject(index.getId(), index)

        login = DTMLMethod()
        login.munge('Please log in first.')
        login._setId('login_form')
        root._setObject(login.getId(), login)

        protected = DTMLMethod()
        protected._View_Permission = ('Manager', )
        protected.munge('This is the protected view')
        protected._setId('protected')
        root._setObject(protected.getId(), protected)

        req = makerequest(root, StringIO())
        self._finally = req.close

        credentials = quote(base64_encode(b'abraham:pass-w'))

        return root, cc, req, credentials
Пример #27
0
    def setUp(self):
        root = Folder()
        self.root = root
        root.isTopLevelPrincipiaApplicationObject = 1  # User folder needs this
        root.getPhysicalPath = lambda: ()  # hack
        root._View_Permission = ('Anonymous', )

        users = UserFolder()
        users._setId('acl_users')
        users._doAddUser('abraham', 'pass-w', ('Patriarch', ), ())
        users._doAddUser('isaac', 'pass-w', ('Son', ), ())
        root._setObject(users.id, users)

        cc = CookieCrumbler()
        cc.id = 'cookie_authentication'
        root._setObject(cc.id, cc)
        self.cc = getattr(root, cc.id)

        index = DTMLMethod()
        index.munge('This is the default view')
        index._setId('index_html')
        root._setObject(index.getId(), index)

        login = DTMLMethod()
        login.munge('Please log in first.')
        login._setId('login_form')
        root._setObject(login.getId(), login)

        protected = DTMLMethod()
        protected._View_Permission = ('Manager', )
        protected.munge('This is the protected view')
        protected._setId('protected')
        root._setObject(protected.getId(), protected)

        self.responseOut = StringIO()
        self.req = makerequest(root, self.responseOut)

        self.credentials = urllib.quote(
            base64.encodestring('abraham:pass-w').rstrip())
Пример #28
0
  def setUp(self):
    CookieCrumblerTests.setUp(self)
    root = Folder()
    self.root = root
    root.isTopLevelPrincipiaApplicationObject = 1  # User folder needs this
    root.getPhysicalPath = lambda: ()  # hack
    root._View_Permission = ('Anonymous',)

    users = UserFolder()
    users._setId('acl_users')
    users._doAddUser('abraham', 'pass-w', ('Patriarch',), ())
    users._doAddUser('isaac', 'pass-w', ('Son',), ())
    users._doAddUser('abrahammmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm',
                     'pass-wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww',
                     ('Son',), ())
    root._setObject(users.id, users)
    
    cc = CookieCrumbler()
    cc.id = 'cookie_authentication'
    root._setObject(cc.id, cc)
    self.cc = getattr(root, cc.id)

    index = DTMLMethod()
    index.munge('This is the default view')
    index._setId('index_html')
    root._setObject(index.getId(), index)

    login = DTMLMethod()
    login.munge('Please log in first.')
    login._setId('login_form')
    root._setObject(login.getId(), login)

    protected = DTMLMethod()
    protected._View_Permission = ('Manager',)
    protected.munge('This is the protected view')
    protected._setId('protected')
    root._setObject(protected.getId(), protected)

    self.responseOut = StringIO()
    self.req = makerequest(root, self.responseOut)

    self.credentials = urllib.quote(
        base64.encodestring('abraham:pass-w').replace('\012', ''))
Пример #29
0
 def _createZODBClone(self):
     """Create a ZODB (editable) equivalent of this object."""
     return DTMLMethod(self.read(), __name__=self.getId())
Пример #30
0
 def __init__(self, *nv, **kw):
     DTMLMethod.__init__(self, *nv, **kw)