python在这里抱怨什么?

发布于 2024-08-21 10:47:42 字数 1269 浏览 4 评论 0原文

我正在尝试运行 Adob​​e 的示例 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清风挽心 2024-08-28 10:47:42

with 仅在 2.6+ 中可用,或者在 2.5+ 中使用 from __future__ import with_statement

with is only available in 2.6+, or in 2.5+ with from __future__ import with_statement.

瀟灑尐姊 2024-08-28 10:47:42

with 语句是 Python 2.5 中的新增内容。也许您使用的是旧版本?

The with statement is new in Python 2.5. Perhaps you are using an older version?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文