开发者

What's python complaining about here?

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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜