當前位置: 首頁>>代碼示例>>Python>>正文


Python Client.hydrate_website方法代碼示例

本文整理匯總了Python中aspen.testing.client.Client.hydrate_website方法的典型用法代碼示例。如果您正苦於以下問題:Python Client.hydrate_website方法的具體用法?Python Client.hydrate_website怎麽用?Python Client.hydrate_website使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在aspen.testing.client.Client的用法示例。


在下文中一共展示了Client.hydrate_website方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Harness

# 需要導入模塊: from aspen.testing.client import Client [as 別名]
# 或者: from aspen.testing.client.Client import hydrate_website [as 別名]
class Harness(object):
    """A harness to be used in the Aspen test suite itself. Probably not useful to you.
    """

    def __init__(self):
        self.fs = namedtuple('fs', 'www project')
        self.fs.www = FilesystemTree()
        self.fs.project = FilesystemTree()
        self.client = Client(self.fs.www.root, self.fs.project.root)

    def teardown(self):
        self.fs.www.remove()
        self.fs.project.remove()


    # Simple API
    # ==========

    def simple(self, contents='Greetings, program!', filepath='index.html.spt', uripath=None,
            argv=None, **kw):
        """A helper to create a file and hit it through our machinery.
        """
        if filepath is not None:
            self.fs.www.mk((filepath, contents))
        if argv is not None:
            self.client.hydrate_website(argv)

        if uripath is None:
            if filepath is None:
                uripath = '/'
            else:
                uripath = '/' + filepath
                if uripath.endswith('.spt'):
                    uripath = uripath[:-len('.spt')]
                for indexname in self.client.website.indices:
                    if uripath.endswith(indexname):
                        uripath = uripath[:-len(indexname)]
                        break

        return self.client.GET(uripath, **kw)

    def make_request(self, *a, **kw):
        kw['return_after'] = 'dispatch_request_to_filesystem'
        kw['want'] = 'request'
        return self.simple(*a, **kw)

    def make_dispatch_result(self, *a, **kw):
        kw['return_after'] = 'dispatch_request_to_filesystem'
        kw['want'] = 'dispatch_result'
        return self.simple(*a, **kw)
開發者ID:Acidburn0zzz,項目名稱:aspen-python,代碼行數:52,代碼來源:harness.py

示例2: __init__

# 需要導入模塊: from aspen.testing.client import Client [as 別名]
# 或者: from aspen.testing.client.Client import hydrate_website [as 別名]
 def __init__(self, *a, **kw):
     Client.__init__(self, *a, **kw)
     Client.website = Client.hydrate_website(self)
開發者ID:beerm,項目名稱:gratipay.com,代碼行數:5,代碼來源:__init__.py

示例3: Harness

# 需要導入模塊: from aspen.testing.client import Client [as 別名]
# 或者: from aspen.testing.client.Client import hydrate_website [as 別名]
class Harness(object):
    """A harness to be used in the Aspen test suite itself. Probably not useful to you.
    """

    def __init__(self):
        self.fs = namedtuple("fs", "www project")
        self.fs.www = FilesystemTree()
        self.fs.project = FilesystemTree()
        self.client = Client(self.fs.www.root, self.fs.project.root)

    def teardown(self):
        self.fs.www.remove()
        self.fs.project.remove()

    # Simple API
    # ==========

    def simple(self, contents="Greetings, program!", filepath="index.html.spt", uripath=None, argv=None, **kw):
        """A helper to create a file and hit it through our machinery.
        """
        if filepath is not None:
            self.fs.www.mk((filepath, contents))
        if argv is not None:
            self.client.hydrate_website(argv)

        if uripath is None:
            if filepath is None:
                uripath = "/"
            else:
                uripath = "/" + filepath
                if uripath.endswith(".spt"):
                    uripath = uripath[: -len(".spt")]
                for indexname in self.client.website.indices:
                    if uripath.endswith(indexname):
                        uripath = uripath[: -len(indexname)]
                        break

        return self.client.GET(uripath, **kw)

    def make_request(self, *a, **kw):
        kw["return_after"] = "dispatch_request_to_filesystem"
        kw["want"] = "request"
        return self.simple(*a, **kw)

    # Sockets
    # =======

    def make_transport(self, content="", state=0):
        self.fs.www.mk(("echo.sock.spt", content))
        socket = self.make_socket()
        transport = XHRPollingTransport(socket)
        transport.timeout = 0.05  # for testing, could screw up the test
        if state == 1:
            transport.respond(Request(uri="/echo.sock"))
        return transport

    def make_socket_request(self, filename="echo.sock.spt"):
        request = Request(uri="/echo.sock")
        request.website = self.client.website
        request.fs = self.fs.www.resolve(filename)
        return request

    def make_socket(self, filename="echo.sock.spt", channel=None):
        request = self.make_socket_request(filename="echo.sock.spt")
        if channel is None:
            channel = Channel(request.line.uri.path.raw, ThreadedBuffer)
        socket = Socket(request, channel)
        return socket

    def SocketInThread(harness):
        class _SocketInThread(object):
            def __enter__(self, filename="echo.sock.spt"):
                self.socket = harness.make_socket(filename)
                self.socket.loop.start()
                return self.socket

            def __exit__(self, *a):
                self.socket.loop.stop()

        return _SocketInThread()
開發者ID:BigBlueHat,項目名稱:aspen-python,代碼行數:82,代碼來源:harness.py


注:本文中的aspen.testing.client.Client.hydrate_website方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。