Created
March 7, 2009 03:30
-
-
Save btbytes/75207 to your computer and use it in GitHub Desktop.
Wrap Zope objects in a request. From http://article.gmane.org/gmane.comp.web.zope.plone.archetypes.general/2277
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, sys | |
from base64 import encodestring | |
from ZPublisher.Request import Request | |
from ZPublisher.Response import Response | |
from ZPublisher.BaseRequest import RequestContainer | |
from AccessControl.SecurityManagement import newSecurityManager | |
e=os.environ | |
e['SERVER_NAME']= 'localhost' | |
e['SERVER_PORT']= '8080' | |
e['SCRIPT_NAME']= '' | |
def wrap(obj, user=None, password=None, method=''): | |
'''wrap *obj* in a request.''' | |
e['REQUEST_METHOD'] = method | |
r = Request(sys.stdin, e, Response()) | |
r['PARENTS'] = [obj] | |
if user is not None and password is not None: | |
r._auth = 'basic ' + encodestring('%s:%s' % (user,password)) | |
UF = obj.acl_users | |
u = UF.getUser(user) | |
if u is not None: | |
u = u.__of__(UF) | |
newSecurityManager(r, u) | |
r['AUTHENTICATED_USER'] = u | |
return obj.__of__(RequestContainer(REQUEST=r)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment