python在这里抱怨什么?
我正在尝试运行 Adobe 的示例 python 策略服务器脚本,链接到此处: http ://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html
我收到以下错误:
# python flashpolicyd.py --file=policy.xml
File "flashpolicyd.py", line 40
with file(path, 'rb') as f:
^
SyntaxError: invalid syntax
在上下文中:
class policy_server(object):
def __init__(self, port, path):
self.port = port
self.path = path
self.policy = self.read_policy(path)
self.log('Listening on port %d\n' % port)
try:
self.sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
except AttributeError:
# AttributeError catches Python built without IPv6
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
# socket.error catches OS with IPv6 disabled
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.sock.bind(('', port))
self.sock.listen(5)
def read_policy(self, path):
with file(path, 'rb') as f:
我对Python一无所知,所以这可能是非常简单和明显的事情。
I'm trying to run Adobe's sample python policy server script, linked to here: http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html
I'm getting the following error:
# python flashpolicyd.py --file=policy.xml
File "flashpolicyd.py", line 40
with file(path, 'rb') as f:
^
SyntaxError: invalid syntax
In context:
class policy_server(object):
def __init__(self, port, path):
self.port = port
self.path = path
self.policy = self.read_policy(path)
self.log('Listening on port %d\n' % port)
try:
self.sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
except AttributeError:
# AttributeError catches Python built without IPv6
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
# socket.error catches OS with IPv6 disabled
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.sock.bind(('', port))
self.sock.listen(5)
def read_policy(self, path):
with file(path, 'rb') as f:
I know nothing about python, so this may be something very simple and obvious.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
with
仅在 2.6+ 中可用,或者在 2.5+ 中使用from __future__ import with_statement
。with
is only available in 2.6+, or in 2.5+ withfrom __future__ import with_statement
.with
语句是 Python 2.5 中的新增内容。也许您使用的是旧版本?The
with
statement is new in Python 2.5. Perhaps you are using an older version?