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
from App import FactoryDispatcher
from App.ProductContext import ProductContext
from DateTime import DateTime
from OFS import bbb
from OFS.metaconfigure import get_packages_to_initialize
from OFS.metaconfigure import package_initialized
from OFS.userfolder import UserFolder
......@@ -40,10 +41,10 @@ from FindSupport import FindSupport
from interfaces import IApplication
from misc_ import Misc_
try:
if bbb.HAS_ZSERVER:
from webdav.NullResource import NullResource
except ImportError:
NullResource = None
else:
NullResource = bbb.NullResource
LOG = getLogger('Application')
......
......@@ -19,6 +19,7 @@ from AccessControl.class_init import InitializeClass
from App.special_dtml import DTMLFile
from zope.interface import implements
from OFS import bbb
from OFS.FindSupport import FindSupport
from OFS.interfaces import IFolder
from OFS.Lockable import LockableItem
......@@ -27,19 +28,10 @@ from OFS.PropertyManager import PropertyManager
from OFS.role import RoleManager
from OFS.SimpleItem import Item
try:
if bbb.HAS_ZSERVER:
from webdav.Collection import Collection
except ImportError:
class Collection(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
else:
Collection = bbb.Collection
manage_addFolderForm = DTMLFile('dtml/folderAdd', globals())
......
......@@ -54,6 +54,7 @@ from zope.interface.interfaces import ComponentLookupError
from zope.lifecycleevent import ObjectAddedEvent
from zope.lifecycleevent import ObjectRemovedEvent
from OFS import bbb
from OFS.CopySupport import CopyContainer
from OFS.interfaces import IObjectManager
from OFS.Traversable import Traversable
......@@ -65,19 +66,10 @@ from OFS.XMLExportImport import importXML
from OFS.XMLExportImport import exportXML
from OFS.XMLExportImport import magic
try:
if bbb.HAS_ZSERVER:
from webdav.Collection import Collection
except ImportError:
class Collection(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
else:
Collection = bbb.Collection
# Constants: __replaceable__ flags:
NOT_REPLACEABLE = 0
......
......@@ -28,17 +28,17 @@ from App.Dialogs import MessageDialog
from App.Management import Tabs
from App.special_dtml import DTMLFile
from ExtensionClass import Base
from OFS import bbb
from Persistence import Persistent
from Traversable import Traversable
from zExceptions import BadRequest
from zExceptions import Redirect
from ZPublisher.Converters import type_converters
try:
if bbb.HAS_ZSERVER:
from webdav.PropertySheet import DAVPropertySheetMixin
except ImportError:
class DAVPropertySheetMixin(object):
pass
else:
DAVPropertySheetMixin = bbb.DAVPropertySheetMixin
class Virtual:
......@@ -408,11 +408,10 @@ InitializeClass(DefaultProperties)
# import cycles
try:
if bbb.HAS_ZSERVER:
from webdav.PropertySheets import DAVProperties
except ImportError:
class DAVProperties(object):
pass
else:
DAVProperties = bbb.DAVProperties
class PropertySheets(Traversable, Implicit, Tabs):
......
......@@ -51,6 +51,7 @@ from zExceptions import Redirect
from zExceptions.ExceptionFormatter import format_exception
from zope.interface import implements
from OFS import bbb
from OFS.interfaces import IItem
from OFS.interfaces import IItemWithName
from OFS.interfaces import ISimpleItem
......@@ -60,19 +61,10 @@ from OFS.Lockable import LockableItem
from OFS.role import RoleManager
from OFS.Traversable import Traversable
try:
if bbb.HAS_ZSERVER:
from webdav.Resource import Resource
except ImportError:
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
else:
Resource = bbb.Resource
logger = logging.getLogger()
......@@ -276,7 +268,7 @@ class Item(Base,
def manage(self, URL1):
"""
"""
raise Redirect, "%s/manage_main" % URL1
raise Redirect("%s/manage_main" % URL1)
# This keeps simple items from acquiring their parents
# objectValues, etc., when used in simple tree tags.
......
......@@ -26,6 +26,7 @@ from Acquisition import aq_base
from Acquisition import aq_inner
from Acquisition import aq_parent
from Acquisition.interfaces import IAcquirer
from OFS import bbb
from OFS.interfaces import ITraversable, IApplication
from zExceptions import NotFound
from ZPublisher.interfaces import UseTraversalDefault
......@@ -195,10 +196,10 @@ class Traversable:
obj = self
# import time ordering problem
try:
if bbb.HAS_ZSERVER:
from webdav.NullResource import NullResource
except ImportError:
NullResource = None
else:
NullResource = bbb.NullResource
resource = _marker
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):
self.assertRaises(KeyError, app.__bobo_traverse__, request, 'NONESUCH')
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
except ImportError:
NullResource = None
else:
NullResource = bbb.NullResource
if NullResource is None:
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