[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container/Views/VFS - VFSContainerView.py:1.1.4.1 __init__.py:1.1.4.1
Shane Hathaway
shane@cvs.zope.org
Fri, 12 Apr 2002 17:30:49 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Container/Views/VFS
In directory cvs.zope.org:/tmp/cvs-serv20835/lib/python/Zope/App/OFS/Container/Views/VFS
Added Files:
Tag: Zope-3x-branch
VFSContainerView.py __init__.py
Log Message:
Merged Zope3-Server-Branch.
=== Added File Zope3/lib/python/Zope/App/OFS/Container/Views/VFS/VFSContainerView.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""
$Id: VFSContainerView.py,v 1.1.4.1 2002/04/12 21:30:48 shane Exp $
"""
import fnmatch
import time
from Zope.ComponentArchitecture import getView
from Zope.Publisher.VFS.IVFSPublisher import IVFSPublisher
from Zope.Publisher.VFS.IVFSDirectoryPublisher import IVFSDirectoryPublisher
from Zope.App.OFS.Container.IContainer import IContainer
# XXX hard coded object types.
from Zope.App.OFS.Content.File.File import File
from Zope.App.OFS.Folder.Folder import Folder
class VFSContainerView:
__implements__ = IVFSDirectoryPublisher
def __init__(self, context):
""" """
self._container = context
############################################################
# Implementation methods for interface
# Zope.Publisher.VFS.IVFSDirectoryPublisher
def exists(self, name):
'See Zope.Publisher.VFS.IVFSDirectoryPublisher.IVFSDirectoryPublisher'
return self._container.hasObject(name)
def listdir(self, with_stats=0, pattern='*'):
'See Zope.Publisher.VFS.IVFSDirectoryPublisher.IVFSDirectoryPublisher'
t = time.time()
file_list = self._container.objectIds()
# filter them using the pattern
file_list = list(
filter(lambda f, p=pattern, fnm=fnmatch.fnmatch: fnm(f, p),
file_list))
# sort them alphabetically
file_list.sort()
if not with_stats:
result = file_list
else:
result = []
for file in file_list:
obj = self._container.getObject(file)
size = 0
# XXX Should be much nicer
if IContainer.isImplementedBy(obj):
dir_mode = 16384
else:
dir_mode = 0
if hasattr(obj, 'getSize'):
size = obj.getSize()
stat = (dir_mode, 0, 0, 0, 0, 0, size, t, t, t)
if stat is not None:
result.append((file, stat))
return result
def mkdir(self, name, mode=777):
'See Zope.Publisher.VFS.IVFSDirectoryPublisher.IVFSDirectoryPublisher'
if not self._container.hasObject(name):
obj = Folder()
self._container.setObject(name, obj)
def remove(self, name):
'See Zope.Publisher.VFS.IVFSDirectoryPublisher.IVFSDirectoryPublisher'
return self._container.delObject(name)
def rmdir(self, name):
'See Zope.Publisher.VFS.IVFSDirectoryPublisher.IVFSDirectoryPublisher'
return self._container.delObject(name)
def rename(self, old, new):
'See Zope.Publisher.VFS.IVFSDirectoryPublisher.IVFSDirectoryPublisher'
obj = self._container.getObject(old)
self._container.delObject(old)
self._container.setObject(new, obj)
def writefile(self, name, mode, instream, start=0):
'See Zope.Publisher.VFS.IVFSDirectoryPublisher.IVFSDirectoryPublisher'
# XXX This should become much, much smarter later. Based on the
# data and the file ending, it should pick the right object type.
# *** Waiting for Jim's file extension proposal and code to land ***
if not self._container.hasObject(name):
obj = File()
self._container.setObject(name, obj)
else:
obj = self._container.getObject(name)
vfs_view = getView(obj, 'vfs', IVFSPublisher)
vfs_view.write(mode, instream, start)
def check_writable(self, name):
'See Zope.Publisher.VFS.IVFSDirectoryPublisher.IVFSDirectoryPublisher'
# XXX Cheesy band aid :-)
return 1
######################################
# from: Zope.Publisher.VFS.IVFSObjectPublisher.IVFSObjectPublisher
def isdir(self):
'See Zope.Publisher.VFS.IVFSObjectPublisher.IVFSObjectPublisher'
return 1
def isfile(self):
'See Zope.Publisher.VFS.IVFSObjectPublisher.IVFSObjectPublisher'
return 0
def stat(self):
'See Zope.Publisher.VFS.IVFSObjectPublisher.IVFSObjectPublisher'
dir_mode = 16384
t = time.time()
uid = 0
gid = 0
return (dir_mode+0, 0, 0, 0, uid, gid, 4096, t, t, t)
######################################
# from: Zope.Publisher.VFS.IVFSPublisher.IVFSPublisher
def publishTraverse(self, request, name):
'See Zope.Publisher.VFS.IVFSPublisher.IVFSPublisher'
return getattr(self, name)
#
############################################################
=== Added File Zope3/lib/python/Zope/App/OFS/Container/Views/VFS/__init__.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################