Commit 30c921a1 authored by Jim Fulton's avatar Jim Fulton

First crack at new layout and 1.5 support

parent 7992d44e
"""Access control package""" """Access control package"""
__version__='$Revision: 1.58 $'[11:-2] __version__='$Revision: 1.59 $'[11:-2]
import Globals, App.Undo, socket, regex import Globals, App.Undo, socket, regex
from PersistentMapping import PersistentMapping from Globals import HTMLFile, MessageDialog, Persistent, PersistentMapping
from Persistence import Persistent
from Globals import HTMLFile, MessageDialog
from string import join,strip,split,lower from string import join,strip,split,lower
from App.Management import Navigation, Tabs from App.Management import Navigation, Tabs
from Acquisition import Implicit from Acquisition import Implicit
......
from DateTime import DateTime
"""Global definitions""" """Global definitions"""
__version__='$Revision: 1.19 $'[11:-2] __version__='$Revision: 1.20 $'[11:-2]
import sys, os import sys, os
from DateTime import DateTime from DateTime import DateTime
...@@ -23,8 +23,8 @@ except: ...@@ -23,8 +23,8 @@ except:
SOFTWARE_URL=sys.modules['__builtin__'].SOFTWARE_URL='' SOFTWARE_URL=sys.modules['__builtin__'].SOFTWARE_URL=''
from BoboPOS2 import Persistent, PickleDictionary
from SingleThreadedTransaction import PickleDictionary, Persistent from BoboPOS2.PersistentMapping import PersistentMapping
import DocumentTemplate, MethodObject import DocumentTemplate, MethodObject
from AccessControl.PermissionRole import PermissionRole from AccessControl.PermissionRole import PermissionRole
...@@ -170,76 +170,3 @@ def getitems(o,names): ...@@ -170,76 +170,3 @@ def getitems(o,names):
r.append(v) r.append(v)
return r return r
##########################################################################
#
# Log
#
# $Log: Globals.py,v $
# Revision 1.19 1998/11/13 20:23:45 jeffrey
# and fixed the getitems() function
#
# Revision 1.18 1998/11/13 20:22:34 jeffrey
# added jim's "attrget", and Selector/MultipleSelector classes
#
# Revision 1.17 1998/10/02 15:00:22 jim
# Added "DevelopmentMode" that auto-reloads HTMLFile objects.
#
# Revision 1.16 1998/09/29 19:22:03 jim
# Added Acquisition
#
# Revision 1.15 1998/05/26 22:28:14 jim
# Fixed stupid bug in bobobase_modification_time
#
# Revision 1.14 1998/05/22 22:25:42 jim
# Moved some DB-related methods from ObjectManager and SimpleItem and stuffed them
# right into Persistent here.
#
# Revision 1.13 1998/05/08 14:52:20 jim
# Modified default class init to work with new permission machinery.
#
# Revision 1.12 1998/01/08 17:38:03 jim
# Added class initialization machinery to:
#
# - Make sure HTMLFile instances got a __name__ that matched the name
# they were assigned to in the class, and
#
# - Give HTMLFile and Python methods whos names are 'manage' or
# begin with 'manage_' a __roles__ of ('Manager',)
#
# Revision 1.11 1997/12/23 15:08:20 jim
# Changed HTMLFile to use method protocol rather than acquisition
# protocol.
#
# Revision 1.10 1997/12/17 16:36:50 jim
# Changed HTML file to support passing in globals()
#
# Revision 1.9 1997/11/21 19:33:45 brian
# Fixed out-of-date debugger support to add correct SH, CH, SU
#
# Revision 1.8 1997/11/07 17:12:15 jim
# Added SesionNameName.
#
# Revision 1.7 1997/09/15 17:03:53 jim
# Got rid of private.
#
# Revision 1.6 1997/09/02 21:39:43 jim
# Moved MessageDialog to end to deal with recursion in module imports.
#
# Revision 1.5 1997/08/28 19:32:36 jim
# Jim told Paul to do it
#
# Revision 1.4 1997/08/13 22:14:04 jim
# *** empty log message ***
#
# Revision 1.3 1997/08/13 21:42:45 jim
# Added back specialized HTMLFile
#
# Revision 1.2 1997/08/13 19:04:00 jim
# *** empty log message ***
#
# Revision 1.1 1997/08/13 18:58:39 jim
# initial
#
#
...@@ -7,46 +7,27 @@ ...@@ -7,46 +7,27 @@
# rights reserved. # rights reserved.
# #
############################################################################## ##############################################################################
import sys, dcdb, ni import sys, dcdb
dcdb.debug() # Make it easy to set a breakpoint near here. dcdb.debug() # Make it easy to set a breakpoint near here.
import SimpleDB, Sync, TJar, SingleThreadedTransaction, os import os
from BoboPOS2 import SimpleDB, TJar, SingleThreadedTransaction
class SyncDB(SimpleDB.Default, Sync.Synchronized):
pass
SimpleDB.Default=SyncDB
import Globals import Globals
try:
import thread
Globals.application_lock=thread.allocate_lock()
__bobo_before__=Globals.application_lock.acquire
__bobo_after__ =Globals.application_lock.release
except: pass
import OFS.Application import OFS.Application
import TreeDisplay.TreeTag import TreeDisplay.TreeTag
import Scheduler.Scheduler import Scheduler.Scheduler
# Setup support for broken objects: # Setup support for broken objects:
import OFS.Uninstalled, PickleJar import OFS.Uninstalled, BoboPOS2.PickleJar
PickleJar.PickleJar.Broken=OFS.Uninstalled.Broken BoboPOS2.PickleJar.PickleJar.Broken=OFS.Uninstalled.Broken
# Open the application database # Open the application database
Bobobase=OFS.Application.open_bobobase() Bobobase=OFS.Application.open_bobobase()
SessionBase=Globals.SessionBase=TJar.TM(Bobobase) SessionBase=Globals.SessionBase=TJar.TM(Bobobase)
# hack Python __str__ method into the record class.
# This needs to be done better in the future.
import Record, string
Record.Record.__str__=lambda r, j=string.join, m=map, s=str: j(m(s,r),', ')
del Record
del string
SingleThreadedTransaction.Transaction.commit=SessionBase.committer() SingleThreadedTransaction.Transaction.commit=SessionBase.committer()
bobo_application=app=Bobobase['Application'] bobo_application=app=Bobobase['Application']
...@@ -57,71 +38,3 @@ if os.environ.has_key('PRINCIPIA_HIDE_TRACEBACKS'): ...@@ -57,71 +38,3 @@ if os.environ.has_key('PRINCIPIA_HIDE_TRACEBACKS'):
if os.environ.has_key('PRINCIPIA_REALM'): if os.environ.has_key('PRINCIPIA_REALM'):
__bobo_realm__=os.environ['PRINCIPIA_REALM'] __bobo_realm__=os.environ['PRINCIPIA_REALM']
##############################################################################
# Revision Log
#
# $Log: Main.py,v $
# Revision 1.20 1998/10/21 14:54:37 jim
# Added __str__ method to Record.Record
#
# Revision 1.19 1998/10/21 14:52:34 jim
# Added development mode flag.
#
# Revision 1.18 1998/08/03 14:39:30 jim
# *** empty log message ***
#
# Revision 1.17 1998/08/03 14:31:45 jim
# *** empty log message ***
#
# Revision 1.16 1998/05/08 14:51:32 jim
# Added support for uninstalled products.
#
# Revision 1.15 1998/03/18 20:22:45 jim
# Added support for PRINCIPIA_HIDE_TRACEBACKS and PRINCIPIA_REALM.
#
# Revision 1.14 1997/11/19 20:04:23 brian
# Hmm, removed create flag for TM - seems only to be an issue with old bobobases.
#
# Revision 1.13 1997/11/19 19:59:31 brian
# Added create flag to force creation of .trans file when transaction manager is created.
#
# Revision 1.12 1997/11/11 22:56:33 jim
# Added logic to that causes transaction commits to notify LRT managers.
#
# Revision 1.11 1997/11/07 18:29:06 jim
# Added app alias.
#
# Revision 1.10 1997/11/07 17:32:30 jim
# Moved bobobase open to OFS.Application.
#
# Revision 1.9 1997/11/07 17:13:49 jim
# Added SessionBase.
#
# Revision 1.8 1997/10/31 17:04:18 brian
# *** empty log message ***
#
# Revision 1.7 1997/10/31 15:01:33 brian
# Fixed bug that could cause startup failure: when the bobobase failed to
# find 'Application' it would (on bsdi, anyway) raise AttributeError and
# only KeyError was being caught...
#
# Revision 1.6 1997/09/19 18:23:36 brian
# App nicification
#
# Revision 1.5 1997/09/17 16:17:00 jim
# Added scheduler hook.
#
# Revision 1.4 1997/09/10 15:55:50 jim
# Changed to use title_or_id.
#
# Revision 1.3 1997/09/02 21:22:06 jim
# Added import of TreeDisplay.TreeTag to enable tree tag.
# Changed document creation call.
#
# Revision 1.2 1997/08/28 19:32:36 jim
# Jim told Paul to do it
#
# Revision 1.1 1997/08/13 18:58:39 jim
# initial
#
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
__doc__='''Application support __doc__='''Application support
$Id: Application.py,v 1.73 1998/11/17 22:24:50 brian Exp $''' $Id: Application.py,v 1.74 1998/11/20 18:16:37 jim Exp $'''
__version__='$Revision: 1.73 $'[11:-2] __version__='$Revision: 1.74 $'[11:-2]
import Globals,Folder,os,regex,sys,App.Product, App.ProductRegistry import Globals,Folder,os,regex,sys,App.Product, App.ProductRegistry
...@@ -21,7 +21,7 @@ from string import strip, lower, find, rfind, join ...@@ -21,7 +21,7 @@ from string import strip, lower, find, rfind, join
from DateTime import DateTime from DateTime import DateTime
from AccessControl.User import UserFolder from AccessControl.User import UserFolder
from App.ApplicationManager import ApplicationManager from App.ApplicationManager import ApplicationManager
from Persistence import Persistent from Globals import Persistent
from FindSupport import FindSupport from FindSupport import FindSupport
from ImageFile import ImageFile from ImageFile import ImageFile
from urllib import quote from urllib import quote
...@@ -288,10 +288,6 @@ def install_products(app): ...@@ -288,10 +288,6 @@ def install_products(app):
product=getattr(__import__("Products.%s" % product_name), product_name) product=getattr(__import__("Products.%s" % product_name), product_name)
if (pgetattr(product, 'need_license', None, 1) and
not lic_check(product_name)):
continue
permissions={} permissions={}
new_permissions={} new_permissions={}
for permission, names in pgetattr(product, '__ac_permissions__', ()): for permission, names in pgetattr(product, '__ac_permissions__', ()):
...@@ -361,53 +357,6 @@ def lcd(e): ...@@ -361,53 +357,6 @@ def lcd(e):
return dat return dat
def lic_check(product_name):
default_license=30
path_join =os.path.join
product_dir=path_join(SOFTWARE_HOME,'lib/python/Products')
package_dir=path_join(product_dir, product_name)
bobobase =Globals.Bobobase
try: f=open(path_join(package_dir,'%s.lic' % product_name), 'rb')
except: f, val = None, default_license
if f is not None:
dat=lcd(f.read())
f.close()
if dat is None: name, val = '', default_license
else: [name, val]=dat[:2]
if name != product_name: val=default_license
elif val is None: return 1
if not bobobase.has_key('_t_'): t=bobobase['_t_']={}
else: t=bobobase['_t_']
if not t.has_key(product_name):
t[product_name]=time.time()
bobobase['_t_']=t
if (t[product_name] + (86400.0 * val)) <= time.time():
# License has expired!
product=getattr(__import__("Products.%s" % product_name),
product_name)
for s in pgetattr(product, 'classes', ()):
p=rfind(s,'.')
m='Products.%s.%s' % (product_name, s[:p])
c=s[p+1:]
try: __import__(m)
except:
m=s[:p]
__import__(m)
setattr(sys.modules[m], c, Expired)
return 0
return 1
def pgetattr(product, name, default=install_products, __init__=0): def pgetattr(product, name, default=install_products, __init__=0):
if not __init__ and hasattr(product, name): return getattr(product, name) if not __init__ and hasattr(product, name): return getattr(product, name)
if hasattr(product, '__init__'): if hasattr(product, '__init__'):
...@@ -433,6 +382,9 @@ class Misc_: ...@@ -433,6 +382,9 @@ class Misc_:
############################################################################## ##############################################################################
# #
# $Log: Application.py,v $ # $Log: Application.py,v $
# Revision 1.74 1998/11/20 18:16:37 jim
# First crack at new layout and 1.5 support
#
# Revision 1.73 1998/11/17 22:24:50 brian # Revision 1.73 1998/11/17 22:24:50 brian
# Fixed b/w compatibility test to ensure Product folder is installed so that an # Fixed b/w compatibility test to ensure Product folder is installed so that an
# existing Products folder wont be found via acquisition # existing Products folder wont be found via acquisition
......
"""Document object""" """Document object"""
__version__='$Revision: 1.64 $'[11:-2] __version__='$Revision: 1.65 $'[11:-2]
from Globals import HTML, HTMLFile, MessageDialog from Globals import HTML, HTMLFile, MessageDialog
from string import join,split,strip,rfind,atoi,lower from string import join,split,strip,rfind,atoi,lower
...@@ -8,9 +8,9 @@ from AccessControl.Role import RoleManager ...@@ -8,9 +8,9 @@ from AccessControl.Role import RoleManager
from SimpleItem import Item_w__name__, pretty_tb from SimpleItem import Item_w__name__, pretty_tb
from Acquisition import Explicit from Acquisition import Explicit
import regex, Globals, sys import regex, Globals, sys
import cDocumentTemplate import DocumentTemplate.cDocumentTemplate
class Document(cDocumentTemplate.cDocument, HTML, Explicit, class Document(DocumentTemplate.cDocumentTemplate.cDocument, HTML, Explicit,
RoleManager, Item_w__name__, RoleManager, Item_w__name__,
): ):
""" """ """ """
......
__doc__="""Principia Find support""" __doc__="""Principia Find support"""
__version__='$Revision: 1.3 $'[11:-2] __version__='$Revision: 1.4 $'[11:-2]
import sys, os, string, time, Globals import sys, os, string, time, Globals
from DocumentTemplate.DT_Util import Eval, expr_globals from DocumentTemplate.DT_Util import Eval, expr_globals
from AccessControl.Permission import name_trans from AccessControl.Permission import name_trans
from Globals import HTMLFile from Globals import HTMLFile
from cDocumentTemplate import * from DocumentTemplate.cDocumentTemplate import *
from DateTime import DateTime from DateTime import DateTime
from string import find from string import find
...@@ -180,6 +180,9 @@ def p_name(name): ...@@ -180,6 +180,9 @@ def p_name(name):
############################################################################## ##############################################################################
# #
# $Log: FindSupport.py,v $ # $Log: FindSupport.py,v $
# Revision 1.4 1998/11/20 18:16:37 jim
# First crack at new layout and 1.5 support
#
# Revision 1.3 1998/08/14 20:54:44 brian # Revision 1.3 1998/08/14 20:54:44 brian
# Readded Find support that got overwritten somehow # Readded Find support that got overwritten somehow
# #
......
"""Image object""" """Image object"""
__version__='$Revision: 1.44 $'[11:-2] __version__='$Revision: 1.45 $'[11:-2]
import Globals import Globals
from Globals import HTMLFile, MessageDialog from Globals import HTMLFile, MessageDialog
from AccessControl.Role import RoleManager from AccessControl.Role import RoleManager
from SimpleItem import Item_w__name__ from SimpleItem import Item_w__name__
from Persistence import Persistent from Globals import Persistent
from Acquisition import Implicit from Acquisition import Implicit
from DateTime import DateTime from DateTime import DateTime
import string import string
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
and aquisition relationships via a simple interface. and aquisition relationships via a simple interface.
""" """
__version__='$Revision: 1.5 $'[11:-2] __version__='$Revision: 1.6 $'[11:-2]
import Globals import Globals
...@@ -32,15 +32,6 @@ class Moniker: ...@@ -32,15 +32,6 @@ class Moniker:
def mtype(self): def mtype(self):
return absattr(self.bind().meta_type) return absattr(self.bind().meta_type)
def assert(self):
# Return true if the named object exists
if self.jar is None: jar=Globals.Bobobase._jar
else: jar=Globals.SessionBase[self.jar].jar
for n in self.ids:
if not jar.has_key(n):
return 0
return 1
def bind(self): def bind(self):
# Return the real object named by this moniker # Return the real object named by this moniker
if self.jar is None: jar=Globals.Bobobase._jar if self.jar is None: jar=Globals.Bobobase._jar
...@@ -71,6 +62,9 @@ def absattr(attr): ...@@ -71,6 +62,9 @@ def absattr(attr):
############################################################################## ##############################################################################
# #
# $Log: Moniker.py,v $ # $Log: Moniker.py,v $
# Revision 1.6 1998/11/20 18:16:37 jim
# First crack at new layout and 1.5 support
#
# Revision 1.5 1998/08/14 16:46:36 brian # Revision 1.5 1998/08/14 16:46:36 brian
# Added multiple copy, paste, rename # Added multiple copy, paste, rename
# #
__doc__="""Object Manager __doc__="""Object Manager
$Id: ObjectManager.py,v 1.45 1998/08/14 16:46:36 brian Exp $""" $Id: ObjectManager.py,v 1.46 1998/11/20 18:16:37 jim Exp $"""
__version__='$Revision: 1.45 $'[11:-2] __version__='$Revision: 1.46 $'[11:-2]
import Persistence, App.Management, Acquisition, App.Undo, Globals import App.Management, Acquisition, App.Undo, Globals
import App.FactoryDispatcher import App.FactoryDispatcher
from Globals import HTMLFile, HTMLFile from Globals import HTMLFile, HTMLFile, Persistent
from Globals import MessageDialog, default__class_init__ from Globals import MessageDialog, default__class_init__
from string import find,join,lower,split from string import find,join,lower,split
from urllib import quote from urllib import quote
from DocumentTemplate import html_quote from DocumentTemplate import html_quote
from cgi_module_publisher import type_converters from HTTP_ORB.Converters import type_converters
from DateTime import DateTime from DateTime import DateTime
class ObjectManager( class ObjectManager(
App.Management.Navigation, App.Management.Navigation,
App.Management.Tabs, App.Management.Tabs,
Acquisition.Implicit, Acquisition.Implicit,
Persistence.Persistent, Persistent,
App.Undo.UndoSupport, App.Undo.UndoSupport,
): ):
"""Generic object manager """Generic object manager
...@@ -505,6 +505,9 @@ class ObjectManager( ...@@ -505,6 +505,9 @@ class ObjectManager(
############################################################################## ##############################################################################
# #
# $Log: ObjectManager.py,v $ # $Log: ObjectManager.py,v $
# Revision 1.46 1998/11/20 18:16:37 jim
# First crack at new layout and 1.5 support
#
# Revision 1.45 1998/08/14 16:46:36 brian # Revision 1.45 1998/08/14 16:46:36 brian
# Added multiple copy, paste, rename # Added multiple copy, paste, rename
# #
......
"""Session object""" """Session object"""
__version__='$Revision: 1.21 $'[11:-2] __version__='$Revision: 1.22 $'[11:-2]
import Globals, time import Globals, time
from AccessControl.Role import RoleManager from AccessControl.Role import RoleManager
from Globals import MessageDialog from Globals import MessageDialog
from Persistence import Persistent from Globals import Persistent
from Acquisition import Implicit from Acquisition import Implicit
from OFS.SimpleItem import Item from OFS.SimpleItem import Item
from string import rfind from string import rfind
...@@ -129,6 +129,9 @@ __init__.need_license=1 ...@@ -129,6 +129,9 @@ __init__.need_license=1
############################################################################## ##############################################################################
# #
# $Log: Session.py,v $ # $Log: Session.py,v $
# Revision 1.22 1998/11/20 18:16:37 jim
# First crack at new layout and 1.5 support
#
# Revision 1.21 1998/09/24 20:13:40 jim # Revision 1.21 1998/09/24 20:13:40 jim
# Added checks to prevent moving uncommitted sessions and drafts # Added checks to prevent moving uncommitted sessions and drafts
# #
......
"""Session object""" """Session object"""
__version__='$Revision: 1.21 $'[11:-2] __version__='$Revision: 1.22 $'[11:-2]
import Globals, time import Globals, time
from AccessControl.Role import RoleManager from AccessControl.Role import RoleManager
from Globals import MessageDialog from Globals import MessageDialog
from Persistence import Persistent from Globals import Persistent
from Acquisition import Implicit from Acquisition import Implicit
from OFS.SimpleItem import Item from OFS.SimpleItem import Item
from string import rfind from string import rfind
...@@ -129,6 +129,9 @@ __init__.need_license=1 ...@@ -129,6 +129,9 @@ __init__.need_license=1
############################################################################## ##############################################################################
# #
# $Log: Version.py,v $ # $Log: Version.py,v $
# Revision 1.22 1998/11/20 18:16:37 jim
# First crack at new layout and 1.5 support
#
# Revision 1.21 1998/09/24 20:13:40 jim # Revision 1.21 1998/09/24 20:13:40 jim
# Added checks to prevent moving uncommitted sessions and drafts # Added checks to prevent moving uncommitted sessions and drafts
# #
......
from StructuredText import html_with_references, HTML
##############################################################################
#
# Copyright (c) 1996-1998, Digital Creations, Fredericksburg, VA, USA.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# o Redistributions of source code must retain the above copyright
# notice, this list of conditions, and the disclaimer that follows.
#
# o Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# o All advertising materials mentioning features or use of this
# software must display the following acknowledgement:
#
# This product includes software developed by Digital Creations
# and its contributors.
#
# o Neither the name of Digital Creations nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS AND CONTRIBUTORS *AS IS*
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL
# CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
#
#
# If you have questions regarding this software, contact:
#
# Digital Creations, L.C.
# 910 Princess Ann Street
# Fredericksburge, Virginia 22401
#
# info@digicool.com
#
# (540) 371-6909
#
##############################################################################
__version__='$Revision: 1.1 $'[11:-2]
import regex
from string import atoi, atol, atof, join, split, strip
def field2string(v):
if hasattr(v,'read'): v=v.read()
else: v=str(v)
return v
def field2text(v, nl=regex.compile('\r\n\|\n\r').search):
if hasattr(v,'read'): v=v.read()
else: v=str(v)
l=nl(v)
if l < 0: return v
r=[]
s=0
while l >= s:
r.append(v[s:l])
s=l+2
l=nl(v,s)
r.append(v[s:])
return join(r,'\n')
def field2required(v):
if hasattr(v,'read'): v=v.read()
else: v=str(v)
if strip(v): return v
raise ValueError, 'No input for required field<p>'
def field2int(v):
if hasattr(v,'read'): v=v.read()
else: v=str(v)
# we can remove the check for an empty string when we go to python 1.4
if v: return atoi(v)
raise ValueError, 'Empty entry when <strong>integer</strong> expected'
def field2float(v):
if hasattr(v,'read'): v=v.read()
else: v=str(v)
# we can remove the check for an empty string when we go to python 1.4
if v: return atof(v)
raise ValueError, (
'Empty entry when <strong>floating-point number</strong> expected')
def field2long(v):
if hasattr(v,'read'): v=v.read()
else: v=str(v)
# we can remove the check for an empty string when we go to python 1.4
if v: return atol(v)
raise ValueError, 'Empty entry when <strong>integer</strong> expected'
def field2tokens(v):
if hasattr(v,'read'): v=v.read()
else: v=str(v)
return split(v)
def field2lines(v):
return split(field2text(v),'\n')
def field2date(v):
from DateTime import DateTime
if hasattr(v,'read'): v=v.read()
else: v=str(v)
return DateTime(v)
ListType=type([])
def field2list(v):
if type(v) is not ListType: v=[v]
return v
def field2tuple(v):
if type(v) is not ListType: v=(v,)
return tuple(v)
type_converters = {
'float': field2float,
'int': field2int,
'long': field2long,
'string': field2string,
'date': field2date,
'list': field2list,
'tuple': field2tuple,
'required': field2required,
'tokens': field2tokens,
'lines': field2lines,
'text': field2text,
}
This diff is collapsed.
##############################################################################
#
# Copyright (c) 1996-1998, Digital Creations, Fredericksburg, VA, USA.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# o Redistributions of source code must retain the above copyright
# notice, this list of conditions, and the disclaimer that follows.
#
# o Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# o All advertising materials mentioning features or use of this
# software must display the following acknowledgement:
#
# This product includes software developed by Digital Creations
# and its contributors.
#
# o Neither the name of Digital Creations nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS AND CONTRIBUTORS *AS IS*
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL
# CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
#
#
# If you have questions regarding this software, contact:
#
# Digital Creations, L.C.
# 910 Princess Ann Street
# Fredericksburge, Virginia 22401
#
# info@digicool.com
#
# (540) 371-6909
#
##############################################################################
__version__='$Revision: 1.1 $'[11:-2]
import regex
from string import atoi, atol, join, split, strip, rfind
isCGI_NAME = {
'SERVER_SOFTWARE' : 1,
'SERVER_NAME' : 1,
'GATEWAY_INTERFACE' : 1,
'SERVER_PROTOCOL' : 1,
'SERVER_PORT' : 1,
'REQUEST_METHOD' : 1,
'PATH_INFO' : 1,
'PATH_TRANSLATED' : 1,
'SCRIPT_NAME' : 1,
'QUERY_STRING' : 1,
'REMOTE_HOST' : 1,
'REMOTE_ADDR' : 1,
'AUTH_TYPE' : 1,
'REMOTE_USER' : 1,
'REMOTE_IDENT' : 1,
'CONTENT_TYPE' : 1,
'CONTENT_LENGTH' : 1,
}.has_key
class Request:
"""\
Model HTTP request data.
This object provides access to request data. This includes, the
input headers, form data, server data, and cookies.
Request objects are created by the object publisher and will be
passed to published objects through the argument name, REQUEST.
The request object is a mapping object that represents a
collection of variable to value mappings. In addition, variables
are divided into four categories:
- Environment variables
These variables include input headers, server data, and other
request-related data. The variable names are as <a
href="http://hoohoo.ncsa.uiuc.edu/cgi/env.html">specified</a>
in the <a
href="http://hoohoo.ncsa.uiuc.edu/cgi/interface.html">CGI
specification</a>
- Form data
These are data extracted from either a URL-encoded query
string or body, if present.
- Cookies
These are the cookie data, if present.
- Other
Data that may be set by an application object.
The form attribute of a request is actually a Field Storage
object. When file uploads are used, this provides a richer and
more complex interface than is provided by accessing form data as
items of the request. See the FieldStorage class documentation
for more details.
The request object may be used as a mapping object, in which case
values will be looked up in the order: environment variables,
other variables, form data, and then cookies.
"""
def __init__(self,environ,form,stdin):
self.environ=environ
self.other=form
self.stdin=stdin
have_env=environ.has_key
b=script=strip(environ['SCRIPT_NAME'])
while b and b[-1]=='/': b=b[:-1]
p = rfind(b,'/')
if p >= 0: b=b[:p+1]
else: b=''
while b and b[0]=='/': b=b[1:]
if have_env('SERVER_URL'):
server_url=strip(environ['SERVER_URL'])
else:
if have_env('HTTPS') and (
environ['HTTPS'] == "on" or environ['HTTPS'] == "ON"):
server_url='https://'
elif (have_env('SERVER_PORT_SECURE') and
environ['SERVER_PORT_SECURE'] == "1"):
server_url='https://'
else: server_url='http://'
if have_env('HTTP_HOST'):
server_url=server_url+strip(environ['HTTP_HOST'])
else:
server_url=server_url+strip(environ['SERVER_NAME'])
server_port=environ['SERVER_PORT']
if server_port!='80': server_url=server_url+':'+server_port
if server_url[-1:]=='/': server_url=server_url[:-1]
self.base="%s/%s" % (server_url,b)
while script[:1]=='/': script=script[1:]
if script: self.script="%s/%s" % (server_url,script)
else: self.script=server_url
def __setitem__(self,key,value):
"""Set application variables
This method is used to set a variable in the requests "other"
category.
"""
self.other[key]=value
set=__setitem__
def __str__(self):
def str(self,name):
dict=getattr(self,name)
return "%s:\n\t%s\n\n" % (
name,
join(
map(lambda k, d=dict: "%s: %s" % (k, `d[k]`), dict.keys()),
"\n\t"
)
)
return "%s\n%s\n" % (
str(self,'form'),str(self,'environ'))
__repr__=__str__
def __getitem__(self,key,
default=isCGI_NAME, # Any special internal marker will do
URLmatch=regex.compile('URL[0-9]$').match,
BASEmatch=regex.compile('BASE[0-9]$').match,
):
"""Get a variable value
Return a value for the required variable name.
The value will be looked up from one of the request data
categories. The search order is environment variables,
other variables, form data, and then cookies.
""" #"
other=self.other
if other.has_key(key):
if key=='REQUEST': return self
return other[key]
if key[:1]=='U' and URLmatch(key) >= 0 and other.has_key('URL'):
n=ord(key[3])-ord('0')
URL=other['URL']
for i in range(0,n):
l=rfind(URL,'/')
if l >= 0: URL=URL[:l]
else: raise KeyError, key
other[key]=URL
return URL
if isCGI_NAME(key) or key[:5] == 'HTTP_':
environ=self.environ
if environ.has_key(key): return environ[key]
return ''
if key=='REQUEST': return self
if key[:1]=='B' and BASEmatch(key) >= 0 and other.has_key('URL'):
n=ord(key[4])-ord('0')
if n:
v=self.script
while v[-1:]=='/': v=v[:-1]
v=join([v]+self.steps[:n-1],'/')
else:
v=self.base
while v[-1:]=='/': v=v[:-1]
other[key]=v
return v
if default is not isCGI_NAME: # Check marker
return default
raise KeyError, key
__getattr__=get=__getitem__
def has_key(self,key):
return self.get(key, Request) is not Request
'''CGI Response Output formatter '''CGI Response Output formatter
$Id: Response.py,v 1.41 1998/11/10 21:45:13 amos Exp $''' $Id: Response.py,v 1.42 1998/11/20 18:16:36 jim Exp $'''
# #
# Copyright (c) 1996-1998, Digital Creations, Fredericksburg, VA, USA. # Copyright (c) 1996-1998, Digital Creations, Fredericksburg, VA, USA.
# All rights reserved. # All rights reserved.
...@@ -51,7 +51,7 @@ $Id: Response.py,v 1.41 1998/11/10 21:45:13 amos Exp $''' ...@@ -51,7 +51,7 @@ $Id: Response.py,v 1.41 1998/11/10 21:45:13 amos Exp $'''
# #
# (540) 371-6909 # (540) 371-6909
# #
__version__='$Revision: 1.41 $'[11:-2] __version__='$Revision: 1.42 $'[11:-2]
import string, types, sys, regex import string, types, sys, regex
from string import find, rfind, lower, upper, strip, split, join, translate from string import find, rfind, lower, upper, strip, split, join, translate
...@@ -600,7 +600,7 @@ class Response: ...@@ -600,7 +600,7 @@ class Response:
return join(headersl,'\n') return join(headersl,'\n')
def __repr__(self): def __repr__(self):
return 'CGIResponse(%s)' % `self.body` return 'Response(%s)' % `self.body`
def flush(self): pass def flush(self): pass
......
from publish import publish_module from Publish import publish_module
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment