什么是python在这抱怨?

时间:2010-02-09 19:37:52

标签: python flash sockets policyfiles

我正在尝试运行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一无所知,所以这可能是非常简单明了的事情。

2 个答案:

答案 0 :(得分:6)

with仅适用于2.6+或2.5及from __future__ import with_statement

答案 1 :(得分:1)

with语句是Python 2.5中的新功能。也许您使用的是旧版本?