如何拒绝访问给定目录的所有子目录?(允许手动修改目录树中单个项目的访问权限.)
我尝试用<Directory(Match)>
指令来做.服务器配置(000-sites-enabled)如下所示:
DocumentRoot /var/www
<Directory /var/www>
Allow from all
Deny from none
Order deny,allow
</Directory>
<Directory /var/www/*>
Deny from all
</Directory>
Run Code Online (Sandbox Code Playgroud)
查询到http://localhost/
成功地显示/var/www/index.html
和所有查询到任何子目录失败.
问题是:对httproot中的文件的任何查询都会失败 - 即请求http://localhost/index.html
将导致403 Forbidden
.
该<Directory(Match)>
指令似乎实际匹配的目录和文件!?
为了看看这是否属实,我试过:
<Directory /var/www/i*>
Deny from all
</Directory>
Run Code Online (Sandbox Code Playgroud)
这拒绝仅访问以"i"开头的文件/目录.
有没有办法改变这种行为,<Directory>
只让匹配目录?还有另一种方法可以实现所有子目录被拒绝吗?(除了手动拒绝所有文件或手动启用所有文件)
我想创建一个setup.py
文件,自动将构建时依赖项解析为numpy(用于编译扩展).我的第一个猜测是使用setup_requires
和子类化命令类来导入numpy模块:
from setuptools import setup, Extension
from distutils.command.build import build as _build
class build(_build):
def run(self):
import numpy
print(numpy.get_include())
_build.run(self)
setup(
name='test',
version='0.0',
description='something',
cmdclass={'build':build},
setup_requires=['numpy'],
)
Run Code Online (Sandbox Code Playgroud)
现在,运行python setup.py build
成功编译numpy但然后失败(内部build.run
):
AttributeError: 'module' object has no attribute 'get_include'
Run Code Online (Sandbox Code Playgroud)
但是,如果再次运行相同的命令,该命令现在成功(并且不需要重新编译numpy).
我已经在python {2.6,2.7,3.3}上使用和不使用virtualenv在最新版本的setuptools上进行了测试.
我已经看到使用pkg_resources.resource_filename的解决方法似乎工作得很好,如果我们想要的只是include目录.编辑:只适用于python2!
但是,我现在很好奇.使用setup_requires
有什么警告?可能是因为numpy无法正常工作的原因是什么?对于一些更简单的模块,它似乎没有问题.
尝试修改装饰器不使用a weakref
,我偶然发现了以下行为:
import weakref
class descriptor(object):
def __get__(self, instance, owner):
return proxy(instance)
class proxy(object):
def __init__(self, instance):
self.instance = instance
def __iadd__(self, other):
return self
class A(object):
descr = descriptor()
def is_leaky(test_fn):
a = A()
wr = weakref.ref(a)
test_fn(a)
del a
return wr() is not None
def test1(a):
tmp = a.descr
tmp += object()
def test2(a):
a.descr += object()
print(is_leaky(test1)) # gives False
print(is_leaky(test2)) # gives True!!!
Run Code Online (Sandbox Code Playgroud)
这对我来说似乎很奇怪,因为我希望两种情况都表现得一样.此外,根据我对引用计数和对象生命周期的理解,我确信在这两种情况下都应该释放对象.
我在python2.7和python3.3上测试了它.
这是一个错误还是故意行为?有没有办法让两个调用都有预期的结果(释放有问题的对象)?
我不想使用weakref
in,proxy
因为这会破坏绑定方法的正确对象生存期语义:
a = …
Run Code Online (Sandbox Code Playgroud) python memory-leaks weak-references decorator python-decorators
我正在使用 python 子进程进行 IPC。现在,让我们假设我必须使用subprocess.Popen
来生成另一个进程,所以我不能multiprocessing.Pipe
用于通信。我想到的第一件事是将他们的 STDIO 流与pickle.load
+一起使用pickle.dump
(现在不要担心安全性)。
但是,我注意到,传输速率非常糟糕:我的机器上的顺序为 750KB/s!这比通过通信慢multiprocessing.Pipe
95 倍pickle
,据我所知,它也使用。使用cPickle
也没有任何好处。
(更新:注意,我意识到,这只是在 python2 上的情况!在 python3 上它工作正常。)
为什么这么慢?我怀疑原因是在.dump
/.load
通过 python 文件对象而不是 C 文件描述符中执行 IO 的方式。也许它与GIL有关?
有什么方法可以跨平台获得与 相同的速度multiprocessing.Pipe
吗?
我已经发现,在 linux 上可以使用_multiprocessing.Connection
(或multiprocessing.connection.Connection
在 python3 上)来包装子进程的 STDIO 文件描述符并获得我想要的。但是,这在 win32 上是不可能的,我什至不知道 Mac。
基准:
from __future__ import print_function
from timeit import default_timer
from subprocess import Popen, PIPE
import pickle
import sys
import …
Run Code Online (Sandbox Code Playgroud) python ×2
apache ×1
apache2 ×1
decorator ×1
io ×1
ipc ×1
memory-leaks ×1
numpy ×1
performance ×1
python-2.x ×1
setuptools ×1
subdirectory ×1
wildcard ×1