integrator.filesystem: Python3 fixes

This commit is contained in:
Helmut Merz 2024-09-22 13:25:46 +02:00
parent ee9d062833
commit b866ac4267
4 changed files with 16 additions and 60 deletions

View file

@ -1,34 +1,15 @@
# # cybertools.util.integrator.base
# Copyright (c) 2010 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ Base implementation for accessing external content objects.
Base implementation for accessing external content objects.
$Id$
""" """
import mimetypes import mimetypes
import os import os
from urllib import urlencode from urllib.parse import urlencode
from zope.app.container.contained import Contained from zope.app.container.contained import Contained
from zope.cachedescriptors.property import Lazy from zope.cachedescriptors.property import Lazy
from zope import component from zope import component
from zope.interface import implements from zope.interface import implementer
from cybertools.integrator.interfaces import IContainerFactory from cybertools.integrator.interfaces import IContainerFactory
from cybertools.integrator.interfaces import IItemFactory, IFileFactory from cybertools.integrator.interfaces import IItemFactory, IFileFactory
@ -61,10 +42,9 @@ class ProxyBase(object):
return self.address.rsplit(os.path.sep, 1)[-1] return self.address.rsplit(os.path.sep, 1)[-1]
@implementer(IReadContainer)
class ReadContainer(ProxyBase, Contained): class ReadContainer(ProxyBase, Contained):
implements(IReadContainer)
icon = 'folder' icon = 'folder'
@Lazy @Lazy
@ -112,18 +92,16 @@ class ReadContainer(ProxyBase, Contained):
has_key = __contains__ has_key = __contains__
@implementer(IItem)
class Item(ProxyBase, object): class Item(ProxyBase, object):
implements(IItem)
icon = 'item' icon = 'item'
__parent__ = None __parent__ = None
@implementer(IFile)
class File(Item): class File(Item):
implements(IFile)
def __init__(self, address, contentType, **kw): def __init__(self, address, contentType, **kw):
super(File, self).__init__(address, **kw) super(File, self).__init__(address, **kw)
self.contentType = contentType self.contentType = contentType
@ -141,10 +119,9 @@ class File(Item):
return (mimeTypes.get(self.contentType) or ['unknown'])[0] return (mimeTypes.get(self.contentType) or ['unknown'])[0]
@implementer(IImage)
class Image(File): class Image(File):
implements(IImage)
icon = 'image' icon = 'image'
def getImageSize(self): def getImageSize(self):
@ -174,24 +151,21 @@ class Factory(object):
return self.proxyClass(address, **kw) return self.proxyClass(address, **kw)
@implementer(IContainerFactory)
class ContainerFactory(Factory): class ContainerFactory(Factory):
implements(IContainerFactory)
proxyClass = ReadContainer proxyClass = ReadContainer
@implementer(IItemFactory)
class ItemFactory(Factory): class ItemFactory(Factory):
implements(IItemFactory)
proxyClass = Item proxyClass = Item
@implementer(IFileFactory)
class FileFactory(Factory): class FileFactory(Factory):
implements(IFileFactory)
proxyClass = File # real implementations should also care about images proxyClass = File # real implementations should also care about images

View file

@ -1,23 +1,6 @@
# # cybertools.util.integrator.filesystem
# Copyright (c) 2012 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ Access to objects in the file system.
Access to objects in the file system.
""" """
import os, stat import os, stat
@ -26,7 +9,7 @@ from zope import component
from zope.app.file.image import getImageInfo from zope.app.file.image import getImageInfo
from zope.cachedescriptors.property import Lazy from zope.cachedescriptors.property import Lazy
from zope.contenttype import guess_content_type from zope.contenttype import guess_content_type
from zope.interface import implements, Attribute from zope.interface import Attribute
from cybertools.integrator.base import ContainerFactory, FileFactory from cybertools.integrator.base import ContainerFactory, FileFactory
from cybertools.integrator.base import ReadContainer, File, Image from cybertools.integrator.base import ReadContainer, File, Image

View file

@ -4,8 +4,6 @@ Integrating objects from external systems
Integration of external sources. Integration of external sources.
($Id$)
Getting started Getting started
=============== ===============
@ -101,7 +99,7 @@ A file object has additional attributes/methods.
'index.html' 'index.html'
>>> html.contentType >>> html.contentType
'text/html' 'text/html'
>>> print html.data >>> print(html.data.decode('UTF-8'))
<html>... <html>...
<img src="sub/loops_logo.png" /> <img src="sub/loops_logo.png" />
<a href="sub">Subdirectory</a> <a href="sub">Subdirectory</a>

View file

@ -18,6 +18,7 @@ dependencies = [
"persistent", "persistent",
"pillow", "pillow",
"zope.app.container", "zope.app.container",
"zope.app.file",
"zope.app.rotterdam", "zope.app.rotterdam",
"zope.app.testing", "zope.app.testing",
"zope.authentication", "zope.authentication",