import os, sys
sys.path.append('lib/python')
from ZPublisher.Request import  Request
from ZPublisher.Response import  Response
from ZPublisher.Publish import get_module_info
from base64 import encodestring

e=os.environ
e['SERVER_NAME']= 'localhost'; e['SERVER_PORT']= '8080'
e['SCRIPT_NAME']= ''

try: from Zope import startup # Zope 2.6.1 and above
except ImportError: startup= None
if startup is not None: startup()

(bobo_before, bobo_after, object, realm, debug_mode, err_hook,
     sec_manager, have_transactions)= get_module_info('Zope')

def getRequest(method=''):
  e['REQUEST_METHOD']= method
  request= Request(sys.stdin, e,
		   Response(),
		   )
  request['PARENTS']= [object]
  return request

def getAuthRequest(user,password,method=''):
  r=getRequest(method)
  r._auth='basic ' + encodestring('%s:%s' % (user,password))
  return r
