在python Web应用程序中,我将一些东西打包成zip文件.我想在内存中完全执行此操作,而不需要触摸磁盘.只要我正在创建一个平面目录结构,使用ZipFile.writestr就可以了,但是如何在zip中创建目录呢?
我正在使用python2.4.
以下示例适用于使用Apache的Mac OS X,即我将已翻译的字符串回显.但是在使用lighttpd的Ubuntu上,我得到原始文本"非活动帐户".我已经尝试了各种各样的环境varialbes组合而没有任何运气.它不是文件权限,因为我可以回显.mo文件的内容.
<?php
//$locale = 'sv_SE.UTF-8';
$locale = 'sv_SE';
$dir = dirname(__FILE__);
// File permission is apparantly not a problem as this works...
//echo file_get_contents($dir . '/sv_SE/LC_MESSAGES/flattr.mo');
putenv("LANG=$locale");
putenv("LANGUAGE=$locale");
putenv("LC_ALL=$locale");
putenv("LC_MESSAGES=$locale");
setlocale(LC_ALL, $locale);
setlocale(LC_MESSAGES, $locale);
//setlocale(LANG, $locale);
//setlocale(LANGUAGE, $locale);
bindtextdomain('flattr', $dir);
//bind_textdomain_codeset("flattr", 'UTF-8');
textdomain('flattr');
echo _("Inactive account");
?>
Run Code Online (Sandbox Code Playgroud)
有人有主意吗?
我正在尝试构建页面操作扩展,并需要从弹出窗口加载外部JavaScript库(它需要来自外部域,以便发送正确的cookie).
但是我收到此错误消息:
由于Content-Security-Policy,拒绝从'http://api.flattr.com/js/0.6/load.js?mode=auto'加载脚本.
有没有办法解决?
我想将HTML页面发送到编码为UTF-8的Web浏览器.但是,以下示例失败:
from wsgiref.simple_server import make_server
def app(environ, start_response):
output = "<html><body><p>Räksmörgås</p></body></html>".encode('utf-8')
start_response('200 OK', [
('Content-Type', 'text/html'),
('Content-Length', str(len(output))),
])
return output
port = 8000
httpd = make_server('', port, app)
print("Serving on", port)
httpd.serve_forever()
Run Code Online (Sandbox Code Playgroud)
这是追溯:
Serving on 8000
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/wsgiref/handlers.py", line 75, in run
self.finish_response()
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/wsgiref/handlers.py", line 116, in finish_response
self.write(data)
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/wsgiref/handlers.py", line 202, in write
"write() argument must be a string or bytes"
Run Code Online (Sandbox Code Playgroud)
如果我删除编码并简单地返回python 3 unicode字符串,wsgiref服务器似乎编码在浏览器在请求标头中指定的任何字符集中.但是我想自己拥有这个控件,因为我怀疑我可以期待所有WSGI服务器都这样做.如何返回UTF-8编码的HTML页面?
谢谢!
我正在尝试使用Firefox 3.5和Chrome中实现的HTML5音频元素制作基于Web的媒体播放器.阅读Mozillas文档,省略autobuffer属性应该导致音频src没有被请求:
如果指定,即使没有设置为自动播放,音频也会自动开始下载.这将继续,直到媒体缓存已满,或者已下载整个音频文件,以先到者为准
但是,在服务器端,我注意到正在请求文件.我的示例页面非常简单:
<html>
<body>
<audio src="1.ogg"></audio>
<audio src="2.ogg"></audio>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)