Commit a496dc50 authored by Hanno Schlichting's avatar Hanno Schlichting

Use pkg_resources to determine if ZServer/webdav is available.

There are so many import dependencies between OFS and webdav, it's
otherwise too easy to accidentally cause a cycle and silently break
one module.
parent 37d9dca4
...@@ -27,6 +27,7 @@ from App.ApplicationManager import ApplicationManager ...@@ -27,6 +27,7 @@ from App.ApplicationManager import ApplicationManager
from App import FactoryDispatcher from App import FactoryDispatcher
from App.ProductContext import ProductContext from App.ProductContext import ProductContext
from DateTime import DateTime from DateTime import DateTime
from OFS import bbb
from OFS.metaconfigure import get_packages_to_initialize from OFS.metaconfigure import get_packages_to_initialize
from OFS.metaconfigure import package_initialized from OFS.metaconfigure import package_initialized
from OFS.userfolder import UserFolder from OFS.userfolder import UserFolder
...@@ -40,10 +41,10 @@ from FindSupport import FindSupport ...@@ -40,10 +41,10 @@ from FindSupport import FindSupport
from interfaces import IApplication from interfaces import IApplication
from misc_ import Misc_ from misc_ import Misc_
try: if bbb.HAS_ZSERVER:
from webdav.NullResource import NullResource from webdav.NullResource import NullResource
except ImportError: else:
NullResource = None NullResource = bbb.NullResource
LOG = getLogger('Application') LOG = getLogger('Application')
......
...@@ -19,6 +19,7 @@ from AccessControl.class_init import InitializeClass ...@@ -19,6 +19,7 @@ from AccessControl.class_init import InitializeClass
from App.special_dtml import DTMLFile from App.special_dtml import DTMLFile
from zope.interface import implements from zope.interface import implements
from OFS import bbb
from OFS.FindSupport import FindSupport from OFS.FindSupport import FindSupport
from OFS.interfaces import IFolder from OFS.interfaces import IFolder
from OFS.Lockable import LockableItem from OFS.Lockable import LockableItem
...@@ -27,19 +28,10 @@ from OFS.PropertyManager import PropertyManager ...@@ -27,19 +28,10 @@ from OFS.PropertyManager import PropertyManager
from OFS.role import RoleManager from OFS.role import RoleManager
from OFS.SimpleItem import Item from OFS.SimpleItem import Item
try: if bbb.HAS_ZSERVER:
from webdav.Collection import Collection from webdav.Collection import Collection
except ImportError: else:
class Collection(object): Collection = bbb.Collection
def dav__init(self, request, response):
pass
def dav__validate(self, object, methodname, REQUEST):
pass
def dav__simpleifhandler(self, request, response, method='PUT',
col=0, url=None, refresh=0):
pass
manage_addFolderForm = DTMLFile('dtml/folderAdd', globals()) manage_addFolderForm = DTMLFile('dtml/folderAdd', globals())
......
...@@ -54,6 +54,7 @@ from zope.interface.interfaces import ComponentLookupError ...@@ -54,6 +54,7 @@ from zope.interface.interfaces import ComponentLookupError
from zope.lifecycleevent import ObjectAddedEvent from zope.lifecycleevent import ObjectAddedEvent
from zope.lifecycleevent import ObjectRemovedEvent from zope.lifecycleevent import ObjectRemovedEvent
from OFS import bbb
from OFS.CopySupport import CopyContainer from OFS.CopySupport import CopyContainer
from OFS.interfaces import IObjectManager from OFS.interfaces import IObjectManager
from OFS.Traversable import Traversable from OFS.Traversable import Traversable
...@@ -65,19 +66,10 @@ from OFS.XMLExportImport import importXML ...@@ -65,19 +66,10 @@ from OFS.XMLExportImport import importXML
from OFS.XMLExportImport import exportXML from OFS.XMLExportImport import exportXML
from OFS.XMLExportImport import magic from OFS.XMLExportImport import magic
try: if bbb.HAS_ZSERVER:
from webdav.Collection import Collection from webdav.Collection import Collection
except ImportError: else:
class Collection(object): Collection = bbb.Collection
def dav__init(self, request, response):
pass
def dav__validate(self, object, methodname, REQUEST):
pass
def dav__simpleifhandler(self, request, response, method='PUT',
col=0, url=None, refresh=0):
pass
# Constants: __replaceable__ flags: # Constants: __replaceable__ flags:
NOT_REPLACEABLE = 0 NOT_REPLACEABLE = 0
......
...@@ -28,17 +28,17 @@ from App.Dialogs import MessageDialog ...@@ -28,17 +28,17 @@ from App.Dialogs import MessageDialog
from App.Management import Tabs from App.Management import Tabs
from App.special_dtml import DTMLFile from App.special_dtml import DTMLFile
from ExtensionClass import Base from ExtensionClass import Base
from OFS import bbb
from Persistence import Persistent from Persistence import Persistent
from Traversable import Traversable from Traversable import Traversable
from zExceptions import BadRequest from zExceptions import BadRequest
from zExceptions import Redirect from zExceptions import Redirect
from ZPublisher.Converters import type_converters from ZPublisher.Converters import type_converters
try: if bbb.HAS_ZSERVER:
from webdav.PropertySheet import DAVPropertySheetMixin from webdav.PropertySheet import DAVPropertySheetMixin
except ImportError: else:
class DAVPropertySheetMixin(object): DAVPropertySheetMixin = bbb.DAVPropertySheetMixin
pass
class Virtual: class Virtual:
...@@ -408,11 +408,10 @@ InitializeClass(DefaultProperties) ...@@ -408,11 +408,10 @@ InitializeClass(DefaultProperties)
# import cycles # import cycles
try: if bbb.HAS_ZSERVER:
from webdav.PropertySheets import DAVProperties from webdav.PropertySheets import DAVProperties
except ImportError: else:
class DAVProperties(object): DAVProperties = bbb.DAVProperties
pass
class PropertySheets(Traversable, Implicit, Tabs): class PropertySheets(Traversable, Implicit, Tabs):
......
...@@ -51,6 +51,7 @@ from zExceptions import Redirect ...@@ -51,6 +51,7 @@ from zExceptions import Redirect
from zExceptions.ExceptionFormatter import format_exception from zExceptions.ExceptionFormatter import format_exception
from zope.interface import implements from zope.interface import implements
from OFS import bbb
from OFS.interfaces import IItem from OFS.interfaces import IItem
from OFS.interfaces import IItemWithName from OFS.interfaces import IItemWithName
from OFS.interfaces import ISimpleItem from OFS.interfaces import ISimpleItem
...@@ -60,19 +61,10 @@ from OFS.Lockable import LockableItem ...@@ -60,19 +61,10 @@ from OFS.Lockable import LockableItem
from OFS.role import RoleManager from OFS.role import RoleManager
from OFS.Traversable import Traversable from OFS.Traversable import Traversable
try: if bbb.HAS_ZSERVER:
from webdav.Resource import Resource from webdav.Resource import Resource
except ImportError: else:
class Resource(object): Resource = bbb.Resource
def dav__init(self, request, response):
pass
def dav__validate(self, object, methodname, REQUEST):
pass
def dav__simpleifhandler(self, request, response, method='PUT',
col=0, url=None, refresh=0):
pass
logger = logging.getLogger() logger = logging.getLogger()
...@@ -276,7 +268,7 @@ class Item(Base, ...@@ -276,7 +268,7 @@ class Item(Base,
def manage(self, URL1): def manage(self, URL1):
""" """
""" """
raise Redirect, "%s/manage_main" % URL1 raise Redirect("%s/manage_main" % URL1)
# This keeps simple items from acquiring their parents # This keeps simple items from acquiring their parents
# objectValues, etc., when used in simple tree tags. # objectValues, etc., when used in simple tree tags.
......
...@@ -26,6 +26,7 @@ from Acquisition import aq_base ...@@ -26,6 +26,7 @@ from Acquisition import aq_base
from Acquisition import aq_inner from Acquisition import aq_inner
from Acquisition import aq_parent from Acquisition import aq_parent
from Acquisition.interfaces import IAcquirer from Acquisition.interfaces import IAcquirer
from OFS import bbb
from OFS.interfaces import ITraversable, IApplication from OFS.interfaces import ITraversable, IApplication
from zExceptions import NotFound from zExceptions import NotFound
from ZPublisher.interfaces import UseTraversalDefault from ZPublisher.interfaces import UseTraversalDefault
...@@ -195,10 +196,10 @@ class Traversable: ...@@ -195,10 +196,10 @@ class Traversable:
obj = self obj = self
# import time ordering problem # import time ordering problem
try: if bbb.HAS_ZSERVER:
from webdav.NullResource import NullResource from webdav.NullResource import NullResource
except ImportError: else:
NullResource = None NullResource = bbb.NullResource
resource = _marker resource = _marker
try: try:
......
##############################################################################
#
# Copyright (c) 2002 Zope Foundation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
import pkg_resources
HAS_ZSERVER = True
try:
dist = pkg_resources.get_distribution('ZServer')
except pkg_resources.DistributionNotFound:
HAS_ZSERVER = False
NullResource = None
class Resource(object):
def dav__init(self, request, response):
pass
def dav__validate(self, object, methodname, REQUEST):
pass
def dav__simpleifhandler(self, request, response, method='PUT',
col=0, url=None, refresh=0):
pass
class Collection(Resource):
pass
class DAVPropertySheetMixin(object):
pass
class DAVProperties(object):
pass
...@@ -91,10 +91,11 @@ class ApplicationTests(unittest.TestCase): ...@@ -91,10 +91,11 @@ class ApplicationTests(unittest.TestCase):
self.assertRaises(KeyError, app.__bobo_traverse__, request, 'NONESUCH') self.assertRaises(KeyError, app.__bobo_traverse__, request, 'NONESUCH')
def test___bobo_traverse__attribute_key_miss_R_M_not_GET_POST(self): def test___bobo_traverse__attribute_key_miss_R_M_not_GET_POST(self):
try: from OFS import bbb
if bbb.HAS_ZSERVER:
from webdav.NullResource import NullResource from webdav.NullResource import NullResource
except ImportError: else:
NullResource = None NullResource = bbb.NullResource
if NullResource is None: if NullResource is None:
return return
......
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