当前位置: 首页>>代码示例>>Python>>正文


Python HTTPRequest.HTTPRequest类代码示例

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


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

示例1: __init__

    def __init__(self, path, command, channel, response, stdin=None,
                 environ=None, globbing=None, recursive=0, size=None):

        # we need to store the globbing information to pass it
        # to the ZPublisher and the manage_FTPlist function
        # (ajung)
        self.globbing = globbing
        self.recursive = recursive

        if stdin is None:
            size = 0
            stdin = StringIO()

        if environ is None:
            environ = self._get_env(path, command, channel, stdin, size)

        self._orig_env = environ
        HTTPRequest.__init__(self, stdin, environ, response, clean=1)

        # support for cookies and cookie authentication
        self.cookies = channel.cookies
        if '__ac' not in self.cookies and channel.userid != 'anonymous':
            self.other['__ac_name'] = channel.userid
            self.other['__ac_password'] = channel.password
        for k, v in self.cookies.items():
            if k not in self.other:
                self.other[k] = v
开发者ID:zopefoundation,项目名称:ZServer,代码行数:27,代码来源:FTPRequest.py

示例2: test_default_viewname_overrides_fti

    def test_default_viewname_overrides_fti(self):
        response = HTTPResponse()
        environment = { 'URL': '',
                        'PARENTS': [self.site],
                        'REQUEST_METHOD': 'GET',
                        'SERVER_PORT': '80',
                        'REQUEST_METHOD': 'GET',
                        'steps': [],
                        'SERVER_NAME': 'localhost',
                        '_hacked_path': 0 }
        r = HTTPRequest(StringIO(), environment, response)
        r.other.update(environment)

        # we define a Zope3-style default view name for which a view
        # actually exists
        defineDefaultViewName('index.html', IDummyContent)
        try:
            from zope.component import provideAdapter
            provideAdapter(DummyView, (DummyContent, IBrowserRequest),
                           IBrowserView, 'index.html')
        except ImportError:
            # BBB for Zope 2.8
            from zope.app.tests import ztapi
            ztapi.browserView(IDummyContent, 'index.html', DummyView)

        r.traverse('foo')
        self.assertEqual( r.URL, '/foo/index.html' )
        self.assertEqual( r.response.base, '/foo/' )
开发者ID:,项目名称:,代码行数:28,代码来源:

示例3: test_update_preserves_mimetype

    def test_update_preserves_mimetype(self):
        self.folder.invokeFactory('DDocument', 'mydoc', title="My Doc")
        doc = self.folder.mydoc
        doc.setBody("""
An rst Document
===============

* Which

  * has

  * some

* bullet::

  points.

* for testing""",  mimetype="text/restructured")
        doc.reindexObject()
        mimetype = doc.getField('body').getContentType(doc)
        self.assertEqual(mimetype, 'text/x-rst')

        # update schema for all DDocuments and check if our type is preserved
        request = HTTPRequest(sys.stdin,
                              {'SERVER_NAME': 'test', 'SERVER_PORT': '8080'},
                              {})
        request.form['Archetypes.DDocument'] = True
        request.form['update_all'] = True
        self.portal.archetype_tool.manage_updateSchema(REQUEST=request)
        doc = self.folder.mydoc
        mimetype = doc.getField('body').getContentType(doc)
        self.assertEqual(mimetype, 'text/x-rst')
开发者ID:seanupton,项目名称:Products.Archetypes,代码行数:32,代码来源:test_update_schema.py

示例4: addRequestContainer

def addRequestContainer(app, environ=None):
    """Add the request container with a fake request to the app object's
    acquisition context and return the wrapped app object. Additional request
    environment values can be passed as a dict ``environ``.
    """

    from sys import stdin, stdout
    from ZPublisher.HTTPRequest import HTTPRequest
    from ZPublisher.HTTPResponse import HTTPResponse
    from ZPublisher.BaseRequest import RequestContainer

    from zope.publisher.browser import setDefaultSkin

    if environ is None:
        environ = {}

    environ.setdefault('SERVER_NAME', 'nohost')
    environ.setdefault('SERVER_PORT', 'port')
    environ.setdefault('REQUEST_METHOD', 'GET')

    resp = HTTPResponse(stdout=stdout)
    req = HTTPRequest(stdin, environ, resp)
    req._steps = ['noobject']  # Fake a published object.

    setDefaultSkin(req)

    requestcontainer = RequestContainer(REQUEST=req)
    return app.__of__(requestcontainer)
开发者ID:vipod,项目名称:plone.testing,代码行数:28,代码来源:z2.py

示例5: _executeAsUser

def _executeAsUser(context_path, portal_path, uf_path, user_id, func, *args,
    **kwargs):
    """Reconstruct environment and execute func."""
    transaction = Zope2.zpublisher_transactions_manager  # Supports isDoomed
    transaction.begin()
    app = Zope2.app()
    result = None
    try:
        try:
            portal = app.unrestrictedTraverse(portal_path, None)
            if portal is None:
                raise BadRequest(
                    'Portal path %s not found' % '/'.join(portal_path))
            setSite(portal)

            if uf_path:
                acl_users = app.unrestrictedTraverse(uf_path, None)
                if acl_users is None:
                    raise BadRequest(
                        'Userfolder path %s not found' % '/'.join(uf_path))
                user = acl_users.getUserById(user_id)
                if user is None:
                    raise BadRequest('User %s not found' % user_id)
                newSecurityManager(None, user)

            context = portal.unrestrictedTraverse(context_path, None)
            if context is None:
                raise BadRequest(
                    'Context path %s not found' % '/'.join(context_path))

            # Create a request to work with
            import sys
            from ZPublisher.HTTPResponse import HTTPResponse
            from ZPublisher.HTTPRequest import HTTPRequest
            response = HTTPResponse(stdout=sys.stdout)
            env = {'SERVER_NAME':'fake_server',
                   'SERVER_PORT':'80',
                   'REQUEST_METHOD':'GET'}
            request = HTTPRequest(sys.stdin, env, response)

            # Set values from original request
            original_request = kwargs.get('original_request')
            if original_request:
                for k,v in original_request.items():
                    request.set(k, v)
            context.REQUEST = request

            result = func(context, *args, **kwargs)

            del context.REQUEST #Avoid "can't pickle file objects"
            transaction.commit()
        except:
            transaction.abort()
            raise
    finally:
        noSecurityManager()
        setSite(None)
        app._p_jar.close()
    return result
开发者ID:gforcada,项目名称:plone.app.async,代码行数:59,代码来源:service.py

示例6: decodeQueryString

def decodeQueryString(QueryString):
  """decode *QueryString* into a dictionary, as ZPublisher would do"""
  r= HTTPRequest(None,
         {'QUERY_STRING' : QueryString,
          'SERVER_URL' : '',
          },
         None,1)
  r.processInputs()
  return r.form
开发者ID:Doap,项目名称:plone.app.cmsui,代码行数:9,代码来源:fileupload.py

示例7: _make_request

 def _make_request(self):
     environ = {}
     environ['SERVER_NAME'] = 'foo'
     environ['SERVER_PORT'] = '80'
     environ['REQUEST_METHOD'] = 'GET'
     resp = HTTPResponse(stdout=sys.stdout)
     req = HTTPRequest(stdin=file, environ=environ, response=resp)
     session = SessionMock()
     req.other['SESSION'] = session
     req['ACTUAL_URL'] = 'http://nohost/'
     return req
开发者ID:Haufe-Lexware,项目名称:hl.pas.samlplugin,代码行数:11,代码来源:base.py

示例8: __init__

 def __init__(self,language=None):
     resp = HTTPResponse(stdout=sys.stdout)
     environ={}
     environ['SERVER_NAME']='foo'
     environ['SERVER_PORT']='80'
     environ['REQUEST_METHOD'] = 'GET'
     environ['SCRIPT_NAME']='/foo/test'
     environ['SESSION']=None
     self.SESSION={}
     HTTPRequest.__init__(self,None,environ,resp)
     if language: self.setLanguage(language)
开发者ID:eaudeweb,项目名称:EionetProducts,代码行数:11,代码来源:testsupport.py

示例9: FakeRequest

def FakeRequest(method='GET', add_auth=False, **kwargs):
    environ = {}
    environ.setdefault('SERVER_NAME', 'foo')
    environ.setdefault('SERVER_PORT', '80')
    environ.setdefault('REQUEST_METHOD', method)
    request = HTTPRequest(sys.stdin,
                          environ,
                          HTTPResponse(stdout=StringIO()))
    request.form = kwargs
    if add_auth:
        request.form['_authenticator'] = plone.protect.createToken()
    return request
开发者ID:collective,项目名称:collective.easyform,代码行数:12,代码来源:testSaver.py

示例10: testRequest

def testRequest():
    """Create a new request object. This is based on the code in
    :py:func`Testing.makerequest.makerequest`."""
    import sys
    from ZPublisher.HTTPRequest import HTTPRequest
    from ZPublisher.HTTPResponse import HTTPResponse
    environ = {"SERVER_NAME": "localhost",
               "SERVER_PORT": "80",
               "REQUEST_METHOD": "GET"}
    request = HTTPRequest(sys.stdin, environ, HTTPResponse())
    request._steps = ["Plone"]
    return request
开发者ID:,项目名称:,代码行数:12,代码来源:

示例11: test_Language_with_header

    def test_Language_with_header(self):
        from plone.app.caching.operations.etags import Language

        environ = {'SERVER_NAME': 'example.com', 'SERVER_PORT': '80'}
        response = HTTPResponse()
        request = HTTPRequest(StringIO(), environ, response)
        published = DummyPublished(DummyContext())

        request.environ['HTTP_ACCEPT_LANGUAGE'] = 'en'

        etag = Language(published, request)

        self.assertEqual('en', etag())
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:13,代码来源:test_etags.py

示例12: testTrustedProxies

    def testTrustedProxies(self):
        TEST_ENVIRON = {
            'REQUEST_METHOD': 'GET',
            'SERVER_NAME': 'localhost',
            'SERVER_PORT': '80',
            'REMOTE_ADDR': '127.0.0.1',
            'HTTP_X_FORWARDED_FOR': '10.1.20.30, 192.168.1.100',
            }
        from StringIO import StringIO
        from ZPublisher.HTTPRequest import HTTPRequest, trusted_proxies
        s = StringIO('')

        env = TEST_ENVIRON.copy()
        request = HTTPRequest(s, env, None)
        self.assertEqual(request.getClientAddr(), '127.0.0.1')

        trusted_proxies.append('127.0.0.1')
        request = HTTPRequest(s, env, None)
        self.assertEqual(request.getClientAddr(), '192.168.1.100')

        trusted_proxies[0] = '192.168.1.100' 
        env = TEST_ENVIRON.copy()
        env['REMOTE_ADDR'] = '192.168.1.100'
        request = HTTPRequest(s, env, None)
        self.assertEqual(request.getClientAddr(), '10.1.20.30')

        env = TEST_ENVIRON.copy()
        del env['REMOTE_ADDR']
        request = HTTPRequest(s, env, None)
        self.assertEqual(request.getClientAddr(), '')
开发者ID:wpjunior,项目名称:proled,代码行数:30,代码来源:testHTTPRequest.py

示例13: testRemoveStdinReferences

 def testRemoveStdinReferences(self):
     # Verifies that all references to the input stream go away on
     # request.close().  Otherwise a tempfile may stick around.
     import sys
     from StringIO import StringIO
     s = StringIO(TEST_FILE_DATA)
     env = TEST_ENVIRON.copy()
     start_count = sys.getrefcount(s)
     from ZPublisher.HTTPRequest import HTTPRequest
     req = HTTPRequest(s, env, None)
     req.processInputs()
     self.assertNotEqual(start_count, sys.getrefcount(s))  # Precondition
     req.close()
     self.assertEqual(start_count, sys.getrefcount(s))  # The test
开发者ID:wpjunior,项目名称:proled,代码行数:14,代码来源:testHTTPRequest.py

示例14: testFileIterator

 def testFileIterator(self):
     # checks fileupload object supports the iterator protocol
     # collector entry 1837
     import sys
     from StringIO import StringIO
     s = StringIO(TEST_FILE_DATA)
     env = TEST_ENVIRON.copy()
     from ZPublisher.HTTPRequest import HTTPRequest
     req = HTTPRequest(s, env, None)
     req.processInputs()
     f=req.form.get('file')
     self.assertEqual(list(f),['test\n'])
     f.seek(0)
     self.assertEqual(f.next(),'test\n')
     f.seek(0)
     self.assertEqual(f.xreadlines(),f)
开发者ID:wpjunior,项目名称:proled,代码行数:16,代码来源:testHTTPRequest.py

示例15: makerequest

def makerequest(app, stdout=stdout):
    resp = HTTPResponse(stdout=stdout)
    environ = os.environ.copy()
    environ['SERVER_NAME'] = 'foo'
    environ['SERVER_PORT'] = '80'
    environ['REQUEST_METHOD'] =  'GET'
    req = HTTPRequest(stdin, environ, resp)
    req._steps = ['noobject']  # Fake a published object.
    req['ACTUAL_URL'] = req.get('URL') # Zope 2.7.4
    
    # set Zope3-style default skin so that the request is usable for
    # Zope3-style view look-ups.
    from zope.app.publication.browser import setDefaultSkin
    setDefaultSkin(req)

    requestcontainer = RequestContainer(REQUEST = req)
    return app.__of__(requestcontainer)
开发者ID:wpjunior,项目名称:proled,代码行数:17,代码来源:makerequest.py


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