示例#1
0
    def __init__(
        self,
        headers=None,
        args=None,
        avatar=None,
        uri="/",
        currentSegments=None,
        cookies=None,
        user="",
        password="",
        isSecure=False,
    ):
        """
        Create a FakeRequest instance.

        @param headers: dict of request headers
        @param args: dict of args
        @param avatar: avatar to pass to the FakeSession instance
        @param uri: request URI
        @param currentSegments: list of segments that have "already been located"
        @param cookies: dict of cookies
        @param user: username (like in http auth)
        @param password: password (like in http auth)
        @param isSecure: whether this request represents an HTTPS url
        """
        Componentized.__init__(self)
        self.uri = uri
        if not uri.startswith("/"):
            raise ValueError("uri must be relative with absolute path")
        self.path = uri
        self.prepath = []
        postpath = uri.split("?")[0]
        assert postpath.startswith("/")
        self.postpath = postpath[1:].split("/")
        if currentSegments is not None:
            for seg in currentSegments:
                assert seg == self.postpath[0]
                self.prepath.append(self.postpath.pop(0))
        else:
            self.prepath.append("")
        self.responseHeaders = Headers()
        self.args = args or {}
        self.sess = FakeSession(avatar)
        self.site = FakeSite()
        self.requestHeaders = Headers()
        if headers:
            for k, v in headers.iteritems():
                self.requestHeaders.setRawHeaders(k, [v])
        if cookies is not None:
            self.cookies = cookies
        else:
            self.cookies = {}
        self.user = user
        self.password = password
        self.secure = isSecure
        self.deferred = defer.Deferred()
示例#2
0
    def __init__(self,
                 headers=None,
                 args=None,
                 avatar=None,
                 uri='/',
                 currentSegments=None,
                 cookies=None,
                 user="",
                 password="",
                 isSecure=False):
        """Create a FakeRequest instance.

        headers:
            dict of headers
        args:
            dict of args
        avatar:
            avatar to pass to the FakeSession instance
        uri:
            request URI
        currentSegments:
            list of segments that have "already been located"
        cookies:
            dict of cookies
        user:
            username (like in http auth)
        password:
            password (like in http auth)
        isSecure:
            whether this request represents an HTTPS url
        """
        Componentized.__init__(self)
        self.uri = uri
        self.prepath = []
        postpath = uri.split('?')[0]
        assert postpath.startswith('/')
        self.postpath = postpath[1:].split('/')
        if currentSegments is not None:
            for seg in currentSegments:
                assert seg == self.postpath[0]
                self.prepath.append(self.postpath.pop(0))
        else:
            self.prepath.append('')
        self.headers = headers or {}
        self.args = args or {}
        self.sess = FakeSession(avatar)
        self.site = FakeSite()
        self.received_headers = {}
        if cookies is not None:
            self.cookies = cookies
        else:
            self.cookies = {}
        self.user = user
        self.password = password
        self.secure = isSecure
示例#3
0
    def __init__(self,
                 headers=None,
                 args=None,
                 avatar=None,
                 uri='/',
                 currentSegments=None,
                 cookies=None,
                 user="",
                 password="",
                 isSecure=False):
        """
        Create a FakeRequest instance.

        @param headers: dict of request headers
        @param args: dict of args
        @param avatar: avatar to pass to the FakeSession instance
        @param uri: request URI
        @param currentSegments: list of segments that have "already been located"
        @param cookies: dict of cookies
        @param user: username (like in http auth)
        @param password: password (like in http auth)
        @param isSecure: whether this request represents an HTTPS url
        """
        Componentized.__init__(self)
        self.uri = uri
        if not uri.startswith('/'):
            raise ValueError('uri must be relative with absolute path')
        self.path = uri
        self.prepath = []
        postpath = uri.split('?')[0]
        assert postpath.startswith('/')
        self.postpath = postpath[1:].split('/')
        if currentSegments is not None:
            for seg in currentSegments:
                assert seg == self.postpath[0]
                self.prepath.append(self.postpath.pop(0))
        else:
            self.prepath.append('')
        self.headers = {}
        self.args = args or {}
        self.sess = FakeSession(avatar)
        self.site = FakeSite()
        self.received_headers = {}
        if headers:
            for k, v in headers.items():
                self.received_headers[k.lower()] = v
        if cookies is not None:
            self.cookies = cookies
        else:
            self.cookies = {}
        self.user = user
        self.password = password
        self.secure = isSecure
        self.deferred = defer.Deferred()
示例#4
0
    def __init__(self, setup):
        Componentized.__init__(self)
        self.config = setup.asDict()

        # anyone adapting an IGameServer from a str/int/None will get me
        registerGlobal(self, IGameServer)

        self.rooms = WeakValueDictionary()
        self.players = WeakValueDictionary()

        registerIDs(GameRoom, self.rooms, IGameRoom)
        registerIDs(lambda: explode(), self.players, IPlayer)

        # init required components
        IServerService(self)
        IServerSite(self)

        if not self.config['quiet']:
            from ServeLib.Interfaces import IStatsProcessor
            import ServeLib.Statistics
            IStatsProcessor(self)
示例#5
0
文件: Server.py 项目: isnok/mpmf
    def __init__(self, setup):
        Componentized.__init__(self)
        self.config = setup.asDict()

        # anyone adapting an IGameServer from a str/int/None will get me
        registerGlobal(self, IGameServer)

        self.rooms = WeakValueDictionary()
        self.players = WeakValueDictionary()

        registerIDs(GameRoom, self.rooms, IGameRoom)
        registerIDs(lambda: explode(), self.players, IPlayer)

        # init required components
        IServerService(self)
        IServerSite(self)

        if not self.config['quiet']:
            from ServeLib.Interfaces import IStatsProcessor
            import ServeLib.Statistics
            IStatsProcessor(self)
示例#6
0
 def __init__(self, avatar):
     Componentized.__init__(self)
     self.avatar = avatar
     self.uid = 12345
示例#7
0
文件: testutil.py 项目: bne/squeal
 def __init__(self, avatar):
     Componentized.__init__(self)
     self.avatar = avatar
     self.uid = 12345
示例#8
0
 def __init__(self, name):
     Componentized.__init__(self)
     NamedObject.__init__(self, name)
示例#9
0
 def __init__(self, session):
     Componentized.__init__(self)
     self.session = session
     self.flashed_messages = []
     self.back = None
示例#10
0
文件: session.py 项目: hitsl/bouser
 def __init__(self, session):
     Componentized.__init__(self)
     self.session = session
     self.flashed_messages = []
     self.back = None