• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python core.asString函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中weightless.core.asString函数的典型用法代码示例。如果您正苦于以下问题:Python asString函数的具体用法?Python asString怎么用?Python asString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了asString函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: testServiceConfig

 def testServiceConfig(self):
     c = ServiceConfig(type='api', minVersion="4.2", untilVersion="5.0")
     consume(c.updateConfig(**CONFIG_SERVICES()))
     self.assertEquals(['api.front.example.org', 'alias1', 'alias2'], asList(c.servernames()))
     self.assertEquals('', asString(c.zones()))
     self.assertEquals('    location / {\n        proxy_pass http://__var_af9b2fd9f1c7f17413223dc3c26aeee4_api;\n    }', asString(c.locations()))
     self.assertEquals('    listen 0.0.0.0:80;\n', asString(c.listenLines()))
开发者ID:seecr,项目名称:meresco-distributed,代码行数:7,代码来源:proxytest.py


示例2: testServiceConfigThrottling

 def testServiceConfigThrottling(self):
     c = ServiceConfig(type='api', minVersion="4.2", untilVersion="5.0", path='/main')
     configServices = CONFIG_SERVICES()
     configServices['config']['api.frontend']['throttling'] = {
         '/path': {'max_connections_per_ip' : 10, 'max_connections': 100},
         '/other': {'max_connections_per_ip' : 30, 'max_connections': 150}
     }
     consume(c.updateConfig(**configServices))
     self.assertEquals([
         'limit_conn_zone $binary_remote_addr zone=api-other-byip:10m;',
         'limit_conn_zone $server_name zone=api-other-total:10m;',
         'limit_conn_zone $binary_remote_addr zone=api-path-byip:10m;',
         'limit_conn_zone $server_name zone=api-path-total:10m;'
         ], asString(c.zones()).split('\n'))
     self.assertEquals([
         '    location /main {',
         '        proxy_pass http://__var_af9b2fd9f1c7f17413223dc3c26aeee4_api;',
         '    }',
         '    location /other {',
         '        proxy_pass http://__var_af9b2fd9f1c7f17413223dc3c26aeee4_api;',
         '        limit_conn api-other-byip 30;',
         '        limit_conn api-other-total 150;',
         '    }',
         '    location /path {',
         '        proxy_pass http://__var_af9b2fd9f1c7f17413223dc3c26aeee4_api;',
         '        limit_conn api-path-byip 10;',
         '        limit_conn api-path-total 100;',
         '    }',
         ], asString(c.locations()).split('\n'))
开发者ID:seecr,项目名称:meresco-distributed,代码行数:29,代码来源:proxytest.py


示例3: testLoggedPathsNewStyle

    def testLoggedPathsNewStyle(self):
        log = CallTrace('log')
        def handleRequest(**kwargs):
            yield okPlainText
            yield 'result'
        index = CallTrace('index', methods={'handleRequest':handleRequest})

        observable = be((Observable(),
            (LogCollector(),
                (QueryLogWriter(log=log, scopeNames=('global', 'yesPath')),),
                (LogCollectorScope('global'),
                    (HandleRequestLog(),
                        (PathFilter('/yes'),
                            (LogCollectorScope('yesPath'),
                                (index,),
                            )
                        ),
                        (PathFilter('/no'),
                            (index,),
                        )
                    )
                )
            )
        ))
        result = asString(observable.all.handleRequest(Client=('11.22.33.44', 1234), path='/yes'))
        self.assertEquals(okPlainText+'result', result)
        result = asString(observable.all.handleRequest(Client=('22.33.44.55', 2345), path='/no'))
        self.assertEquals(okPlainText+'result', result)
        result = asString(observable.all.handleRequest(Client=('33.44.55.66', 3456), path='/yes'))
        self.assertEquals(okPlainText+'result', result)
        self.assertEquals(['log', 'log'], log.calledMethodNames())
        self.assertEquals(['/yes', '/yes'], [m.kwargs['path'] for m in log.calledMethods])
开发者ID:seecr,项目名称:meresco-components,代码行数:32,代码来源:querylogwritertest.py


示例4: testUpdateUser

    def testUpdateUser(self):
        action = UserActions(dataDir=self.tempdir)
        dna = be(
            (Observable(),
                (action, ),
            ))

        users = action.listUsers()
        users.append(User(username="johan"))
        action.saveUsers(users)

        self.assertEqual(2, len(action.listUsers()))
        self.assertEqual("", action.getUser("johan").organization)
        response = asString(dna.call.handleRequest(
            Method="POST",
            path="/user.action/update",
            Body=urlencode(dict(
               redirectUri="/go_here_now",
               username="johan",
               organization="Seecr"))))
        self.assertEqual(2, len(action.listUsers()))
        self.assertEqual("Seecr", action.getUser("johan").organization)
        self.assertTrue("Location: /go_here_now?identifier=johan" in response, response)

        response = asString(dna.call.handleRequest(
            Method="POST",
            path="/user.action/update",
            Body=urlencode(dict(
               redirectUri="/go_here_now",
               username="johan",
               organization=""))))
        self.assertEqual("", action.getUser("johan").organization)
开发者ID:seecr,项目名称:meresco-harvester,代码行数:32,代码来源:useractionstest.py


示例5: testShowUserList

    def testShowUserList(self):
        pf = PasswordFile(join(self.tempdir, 'passwd'))
        self.form.addObserver(pf)
        pf.addUser('one', 'password')
        pf.addUser('two', 'password')
        pf.addUser('three', 'password')
        def enrichUser(user):
            user.title = lambda: user.name.title()
        o = CallTrace(onlySpecifiedMethods=True, methods=dict(enrichUser=enrichUser))
        self.form.addObserver(o)

        session = {'user': self.form.loginAsUser('two')}
        session['user'].canEdit = lambda username=None: username not in ['two', 'admin']

        result = asString(self.form.userList(session=session, path='/show/login'))

        self.assertEqualsWS("""<div id="login-user-list">
    <script type="text/javascript">
function deleteUser(username) {
    if (confirm("Are you sure?")) {
        document.removeUser.username.value = username;
        document.removeUser.submit();
    }
}
</script>
<form name="removeUser" method="POST" action="/action/remove">
    <input type="hidden" name="formUrl" value="/show/login"/>
    <input type="hidden" name="username"/>
</form>
    <ul>
        <li>Admin</li>
        <li>One <a href="javascript:deleteUser('one');">delete</a></li>
        <li>Three <a href="javascript:deleteUser('three');">delete</a></li>
        <li>Two</li>
    </ul>
</div>""", result)

        result = asString(self.form.userList(session=session, path='/show/login', userLink='/user'))

        self.assertEqualsWS("""<div id="login-user-list">
    <script type="text/javascript">
function deleteUser(username) {
    if (confirm("Are you sure?")) {
        document.removeUser.username.value = username;
        document.removeUser.submit();
    }
}
</script>
<form name="removeUser" method="POST" action="/action/remove">
    <input type="hidden" name="formUrl" value="/show/login"/>
    <input type="hidden" name="username"/>
</form>
    <ul>
        <li><a href="/user?user=admin">Admin</a></li>
        <li><a href="/user?user=one">One</a> <a href="javascript:deleteUser('one');">delete</a></li>
        <li><a href="/user?user=three">Three</a> <a href="javascript:deleteUser('three');">delete</a></li>
        <li><a href="/user?user=two">Two</a></li>
    </ul>
</div>""", result)
开发者ID:seecr,项目名称:meresco-html,代码行数:59,代码来源:basichtmlloginformtest.py


示例6: testTransparentForAll

 def testTransparentForAll(self):
     def someMessage(*args, **kwargs):
         yield 'text'
     self.observer.methods['someMessage'] = someMessage
     result = asString(self.dna.all.someMessage('arg', kwarg='kwarg'))
     self.assertEquals('text', result)
     result = asString(self.dna.all.someMessage('arg', kwarg='kwarg'))
     self.assertEquals('text', result)
     self.assertEquals(['someMessage', 'someMessage'], self.observer.calledMethodNames())
开发者ID:seecr,项目名称:meresco-components,代码行数:9,代码来源:timedmessagecachetest.py


示例7: testDebugFlagIsRememberedWithCookie

 def testDebugFlagIsRememberedWithCookie(self):
     consume(self.flagCheck.updateConfig(this_service={'readable': True, 'state':{'readable':False}}))
     header, body = asString(self.server.all.handleRequest(ignored='ignored', arguments=dict(debug=['True']), Headers={}, Client=('host', 1234))).split('\r\n\r\n')
     self.assertEquals('RESULT', body)
     headers = parseHeaders(header)
     self.assertTrue('Set-Cookie' in headers,headers)
     self.assertTrue('Expires=' in headers['Set-Cookie'])
     header, body = asString(self.server.all.handleRequest(ignored='ignored', arguments={}, Headers={'Cookie': ';'.join([headers['Set-Cookie'], 'other=cookie'])}, Client=('host', 1234))).split('\r\n\r\n')
     self.assertEquals('RESULT', body)
     self.assertEquals(['handleRequest', 'handleRequest'], self.observer.calledMethodNames())
开发者ID:seecr,项目名称:meresco-distributed,代码行数:10,代码来源:flagchecktest.py


示例8: testBroadcastAddUserToAllObservers

    def testBroadcastAddUserToAllObservers(self):
        values = []
        dna = be(
            (Observable(),
                (BasicHtmlLoginForm(action="/action", loginPath="/"),
                    (CallTrace(methods={'addUser': lambda *args, **kwargs: values.append(("1st", args, kwargs))}),),
                    (CallTrace(methods={'addUser': lambda *args, **kwargs: values.append(("2nd", args, kwargs))}),),
                    (CallTrace(methods={'addUser': lambda *args, **kwargs: values.append(("3rd", args, kwargs))}),),
                )
            )
        )

        asString(dna.all.handleNewUser(session={'user': BasicHtmlLoginForm.User('admin')}, Body=urlencode(dict(password="password", retypedPassword="password", username='nieuw'))))
        self.assertEquals(3, len(values))
开发者ID:seecr,项目名称:meresco-html,代码行数:14,代码来源:basichtmlloginformtest.py


示例9: testListMetadataFormats

 def testListMetadataFormats(self):
     self.init()
     response = self.listMetadataFormats.listMetadataFormats(arguments=dict(
             verb=['ListMetadataFormats'],
         ),
         **self.httpkwargs)
     _, body = asString(response).split("\r\n\r\n")
     self.assertEquals(['oai_dc', 'rdf'], xpath(XML(body), '/oai:OAI-PMH/oai:ListMetadataFormats/oai:metadataFormat/oai:metadataPrefix/text()'))
     response = self.listMetadataFormats.listMetadataFormats(arguments=dict(
             verb=['ListMetadataFormats'],
             identifier=['id0'],
         ),
         **self.httpkwargs)
     _, body = asString(response).split("\r\n\r\n")
     self.assertEquals(['oai_dc'], xpath(XML(body), '/oai:OAI-PMH/oai:ListMetadataFormats/oai:metadataFormat/oai:metadataPrefix/text()'))
开发者ID:seecr,项目名称:meresco-oai,代码行数:15,代码来源:oailistmetadataformatstest.py


示例10: testFileNotFound2

 def testFileNotFound2(self):
     with open(join(self.tempdir, 'a.sf'), 'w') as f:
         f.write('def main(pipe, **kwargs):\n yield pipe')
     d = DynamicHtml([self.tempdir], reactor=CallTrace('Reactor'))
     result = asString(d.handleRequest(scheme='http', netloc='host.nl', path='/a/path', query='?query=something', fragments='#fragments', arguments={'query': 'something'}))
     self.assertTrue(result.startswith('HTTP/1.0 404 Not Found'), result)
     self.assertTrue('File "path" does not exist.' in result, result)
开发者ID:seecr,项目名称:meresco-html,代码行数:7,代码来源:dynamichtmltest.py


示例11: testCreateSession

    def testCreateSession(self):
        called = []
        class MyObserver(Observable):
            def handleRequest(self, *args, **kwargs):
                session = self.ctx.session
                called.append({'args':args, 'kwargs':kwargs, 'session': session})
                yield  utils.okHtml
                yield '<ht'
                yield 'ml/>'
        self.handler.addObserver(MyObserver())
        result = asString(self.handler.handleRequest(RequestURI='/path', Client=('127.0.0.1', 12345), Headers={'a':'b'}))

        self.assertEquals(1, len(called))
        self.assertEqual({}, called[0]['session'])
        session = called[0]['kwargs']['session']
        self.assertEqual({}, session)
        self.assertEquals({'a':'b'}, called[0]['kwargs']['Headers'])
        self.assertTrue(('127.0.0.1', 12345), called[0]['kwargs']['Client'])
        header, body = result.split(utils.CRLF*2,1)
        self.assertEquals('<html/>', body)
        self.assertTrue('Set-Cookie' in header, header)
        headerParts = header.split(utils.CRLF)
        self.assertEquals("HTTP/1.0 200 OK", headerParts[0])
        sessionCookie = [p for p in headerParts[1:] if 'Set-Cookie' in p][0]
        self.assertTrue(sessionCookie.startswith('Set-Cookie: session'))
开发者ID:seecr,项目名称:meresco-components,代码行数:25,代码来源:sessionhandlertest.py


示例12: testInsertHeaderNone

 def testInsertHeaderNone(self):
     def handleRequest(*args, **kwargs):
         yield "HTTP/1.0 200 OK\r\n"
         yield "Header: value\r\n\r\n"
         yield '<ht'
         yield 'ml/>'
     self.assertEqual('HTTP/1.0 200 OK\r\nHeader: value\r\n\r\n<html/>', asString(utils.insertHeader(handleRequest(), None)))
开发者ID:seecr,项目名称:meresco-components,代码行数:7,代码来源:httputilstest.py


示例13: testCreateUser

    def testCreateUser(self):
        observer = CallTrace()
        action = UserActions(dataDir=self.tempdir)
        session = {}
        dna = be(
            (Observable(),
                (action,
                    (observer, )
                ),
            ))

        self.assertEqual(1, len(action.listUsers()))
        response = asString(dna.call.handleRequest(
           Method="POST",
           path="/user.action/create",
           session=session,
           Body=urlencode(dict(
               redirectUri="/go_here_now",
               username="johan",
               domain="domein",
               password1="password",
               password2="password"))))
        self.assertEqual(2, len(action.listUsers()))
        self.assertTrue("Location: /go_here_now?identifier=johan" in response, response)
        self.assertEqual(1, len(observer.calledMethods))
        self.assertEqual({}, session)
开发者ID:seecr,项目名称:meresco-harvester,代码行数:26,代码来源:useractionstest.py


示例14: testGroupsUserFormAdminSelf

    def testGroupsUserFormAdminSelf(self):
        kwargs = {
            'path': '/path/to/form',
            'arguments': {'key': ['value']},
        }
        self.assertEqualsWS("""<div id="usergroups-groups-user-form">
    <form name="groups" method="POST" action="/action/updateGroupsForUser">
        <input type="hidden" name="username" value="bob"/>
        <input type="hidden" name="formUrl" value="/path/to/form?key=value"/>
        <ul>
            <li><label><input type="checkbox" name="groupname" value="admin" checked="checked" disabled="disabled"/>admin</label></li>
            <li><label><input type="checkbox" name="groupname" value="management"  />management</label></li>
            <li><label><input type="checkbox" name="groupname" value="special"  />special</label></li>
            <li><label><input type="checkbox" name="groupname" value="users" checked="checked" />users</label></li>
        </ul>
        <input type="submit" value="Aanpassen"/>
    </form>
</div>""", asString(self.userGroups.groupsUserForm(user=self.adminUser, **kwargs)))
        self.assertEquals([
            dict(checked=True,  description='', disabled=True,  groupname='admin'),
            dict(checked=False, description='', disabled=False, groupname='management'),
            dict(checked=False, description='', disabled=False, groupname='special'),
            dict(checked=True,  description='', disabled=False, groupname='users'),
            ], self.userGroups._groupsForForm(user=self.adminUser, forUsername=self.adminUser.name))
        self.assertTrue(self.userGroups.canEditGroups(user=self.adminUser, forUsername=self.adminUser.name))
开发者ID:seecr,项目名称:meresco-html,代码行数:25,代码来源:usergroupsformtest.py


示例15: testShowChangePasswordFormErrorWithoutUser

    def testShowChangePasswordFormErrorWithoutUser(self):
        session = {}
        result = asString(self.form.changePasswordForm(session=session, path='/show/changepasswordform', arguments={}))

        self.assertEqualsWS("""<div id="login-change-password-form">
    <p class="error">Please login to change password.</p>
</div>""", result)
开发者ID:seecr,项目名称:meresco-html,代码行数:7,代码来源:basichtmlloginformtest.py


示例16: testAutocompleteCSS

 def testAutocompleteCSS(self):
     result = asString(self.auto.handleRequest(
         path='/path/autocomplete.css',
         arguments={}))
     header,body = result.split('\r\n'*2)
     self.assertTrue('jqac-' in body, body[:300])
     self.assertTrue('Content-Type: text/css' in header, header)
开发者ID:seecr,项目名称:meresco-components,代码行数:7,代码来源:autocompletetest.py


示例17: testOpenSearchWithoutHtmlAndPort80

    def testOpenSearchWithoutHtmlAndPort80(self):
        queryTemplate = '/sru?version=1.1&operation=searchRetrieve&query={searchTerms}'
        self.auto = be((Autocomplete(
                host='localhost',
                port=80,
                path='/some/path',
                templateQuery=queryTemplate,
                shortname="Web Search",
                description="Use this web search to search something",
                defaultLimit=50,
                defaultField='lom',
            ),
            (self.observer,),
        ))
        result = asString(self.auto.handleRequest(
            path='/path/opensearchdescription.xml',
            arguments={}))
        header,body = result.split('\r\n'*2)

        self.assertTrue("Content-Type: text/xml" in header, header)
        self.assertEqualsWS("""<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
    <ShortName>Web Search</ShortName>
    <Description>Use this web search to search something</Description>
    <Url type="text/xml" method="get" template="http://localhost/sru?version=1.1&amp;operation=searchRetrieve&amp;query={searchTerms}"/>
    <Url type="application/x-suggestions+json" template="http://localhost/some/path?prefix={searchTerms}"/>
</OpenSearchDescription>""", body)
开发者ID:seecr,项目名称:meresco-components,代码行数:27,代码来源:autocompletetest.py


示例18: testMinimumLength

    def testMinimumLength(self):
        self._setUpAuto(prefixBasedSearchKwargs=dict(minimumLength=5))
        header, body = asString(self.auto.handleRequest(path='/path', arguments={'prefix':['test']})).split('\r\n'*2)

        self.assertTrue("Content-Type: application/x-suggestions+json" in header, header)
        self.assertEquals("""["test", []]""", body)
        self.assertEquals([], [m.name for m in self.observer.calledMethods])
开发者ID:seecr,项目名称:meresco-components,代码行数:7,代码来源:autocompletetest.py


示例19: testQuery

 def testQuery(self):
     def executeQuery(**kwargs):
         raise StopIteration(Response(total=42))
         yield
     index = CallTrace('index',
         emptyGeneratorMethods=['echoedExtraRequestData', 'extraResponseData'],
         methods=dict(executeQuery=executeQuery))
     observable = be((Observable(),
         (LogCollector(),
             (self.handleRequestLog,
                 (SruParser(),
                     (SruHandler(enableCollectLog=True),
                         (index,)
                     )
                 )
             ),
             (self.queryLogWriter,),
         )
     ))
     result = asString(observable.all.handleRequest(
         Method='GET',
         Client=('127.0.0.1', 1234),
         arguments={
             'version': ['1.2'],
             'operation': ['searchRetrieve'],
             'query': ['query'],
             'maximumRecords': ['0'],
         },
         path='/path/sru',
         otherKwarg='value'))
     self.assertTrue('<srw:numberOfRecords>42</srw:numberOfRecords>' in result, result)
     self.assertTrue(isfile(join(self.tempdir, '2009-11-02-query.log')))
     self.assertEquals('2009-11-02T11:25:37Z 127.0.0.1 0.7K 1.000s 42hits /path/sru maximumRecords=0&operation=searchRetrieve&query=query&recordPacking=xml&recordSchema=dc&startRecord=1&version=1.2\n', open(join(self.tempdir, '2009-11-02-query.log')).read())
开发者ID:seecr,项目名称:meresco-components,代码行数:33,代码来源:srulogtest.py


示例20: testOneResult

    def testOneResult(self):
        observer = CallTrace(
            returnValues={
                'getRecord': '<item><title>Test Title</title><link>Test Identifier</link><description>Test Description</description></item>',
            },
            ignoredAttributes=['unknown', 'extraResponseData', 'echoedExtraRequestData'])

        def executeQuery(**kwargs):
            raise StopIteration(Response(total=1, hits=[Hit(1)]))
            yield
        observer.methods['executeQuery'] = executeQuery

        rss = Rss(
            title = 'Test title',
            description = 'Test description',
            link = 'http://www.example.org',
            sortKeys = 'date,,1',
            maximumRecords = '15',
        )
        rss.addObserver(observer)

        result = asString(rss.handleRequest(RequestURI='/?query=aQuery'))
        self.assertEqualsWS(RSS % """<item>
        <title>Test Title</title>
        <link>Test Identifier</link>
        <description>Test Description</description>
        </item>""", result)
开发者ID:seecr,项目名称:meresco-components,代码行数:27,代码来源:rsstest.py



注:本文中的weightless.core.asString函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python core.be函数代码示例发布时间:2022-05-26
下一篇:
Python utils.parse_datetime函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap