示例#1
0
def mimes_initialize():
    global mimes_initialized
    if mimes_initialized:
        return
    mimes_initialized = True
    # Augment known mime-types.
    here = os.path.dirname(os.path.abspath(__file__))
    add_files([os.path.join(here, 'mime.types')])
示例#2
0
 def test_add_two_files(self):
     ntypes = len(mimetypes.types_map)
     contenttype.add_files([MIME_TYPES_1, MIME_TYPES_2])
     ctype, encoding = contenttype.guess_content_type("foo.ztmt-1")
     self.assert_(encoding is None)
     self.assertEqual(ctype, "text/x-vnd.zope.test-mime-type-1")
     ctype, encoding = contenttype.guess_content_type("foo.ztmt-2")
     self.assert_(encoding is None)
     self.assertEqual(ctype, "text/x-vnd.zope.test-mime-type-2")
     self.check_types_count(2)
示例#3
0
 def test_guess_content_type(self):
     from zope.contenttype import add_files
     from zope.contenttype import guess_content_type
     filename = self._getFilename('mime.types-1')
     add_files([filename])
     ctype, encoding = guess_content_type(body=b'text file')
     self.assertEqual(ctype, "text/plain")
     ctype, encoding = guess_content_type(body=b'\001binary')
     self.assertEqual(ctype, "application/octet-stream")
     ctype, encoding = guess_content_type()
     self.assertEqual(ctype, "text/x-unknown-content-type")
 def test_guess_content_type(self):
     from zope.contenttype import add_files
     from zope.contenttype import guess_content_type
     filename = self._getFilename('mime.types-1')
     add_files([filename])
     ctype, encoding = guess_content_type(body=b'text file')
     self.assertEqual(ctype, "text/plain")
     ctype, encoding = guess_content_type(body=b'\001binary')
     self.assertEqual(ctype, "application/octet-stream")
     ctype, encoding = guess_content_type()
     self.assertEqual(ctype, "text/x-unknown-content-type")
示例#5
0
 def test_add_one_file(self):
     from zope.contenttype import add_files
     from zope.contenttype import guess_content_type
     filename = self._getFilename('mime.types-1')
     add_files([filename])
     ctype, encoding = guess_content_type("foo.ztmt-1")
     self.assertTrue(encoding is None)
     self.assertEqual(ctype, "text/x-vnd.zope.test-mime-type-1")
     ctype, encoding = guess_content_type("foo.ztmt-1.gz")
     self.assertEqual(encoding, "gzip")
     self.assertEqual(ctype, "text/x-vnd.zope.test-mime-type-1")
     self._check_types_count(1)
 def test_add_one_file(self):
     from zope.contenttype import add_files
     from zope.contenttype import guess_content_type
     filename = self._getFilename('mime.types-1')
     add_files([filename])
     ctype, encoding = guess_content_type("foo.ztmt-1")
     self.assertTrue(encoding is None)
     self.assertEqual(ctype, "text/x-vnd.zope.test-mime-type-1")
     ctype, encoding = guess_content_type("foo.ztmt-1.gz")
     self.assertEqual(encoding, "gzip")
     self.assertEqual(ctype, "text/x-vnd.zope.test-mime-type-1")
     self._check_types_count(1)
示例#7
0
 def test_add_two_files(self):
     from zope.contenttype import add_files
     from zope.contenttype import guess_content_type
     filename1 = self._getFilename('mime.types-1')
     filename2 = self._getFilename('mime.types-2')
     add_files([filename1, filename2])
     ctype, encoding = guess_content_type("foo.ztmt-1")
     self.assertTrue(encoding is None)
     self.assertEqual(ctype, "text/x-vnd.zope.test-mime-type-1")
     ctype, encoding = guess_content_type("foo.ztmt-2")
     self.assertTrue(encoding is None)
     self.assertEqual(ctype, "text/x-vnd.zope.test-mime-type-2")
     self._check_types_count(2)
 def test_add_two_files(self):
     from zope.contenttype import add_files
     from zope.contenttype import guess_content_type
     filename1 = self._getFilename('mime.types-1')
     filename2 = self._getFilename('mime.types-2')
     add_files([filename1, filename2])
     ctype, encoding = guess_content_type("foo.ztmt-1")
     self.assertTrue(encoding is None)
     self.assertEqual(ctype, "text/x-vnd.zope.test-mime-type-1")
     ctype, encoding = guess_content_type("foo.ztmt-2")
     self.assertTrue(encoding is None)
     self.assertEqual(ctype, "text/x-vnd.zope.test-mime-type-2")
     self._check_types_count(2)
示例#9
0
def root_handler(config):
    """ Mutate the configuration with defaults and perform
    fixups of values that require knowledge about configuration
    values outside of their context.
    """

    # Set environment variables
    for k,v in config.environment.items():
        os.environ[k] = v

    # Add directories to the pythonpath
    instancelib = os.path.join(config.instancehome, 'lib', 'python')
    if instancelib not in config.path:
        if os.path.isdir(instancelib):
            config.path.append(instancelib)
    path = config.path[:]
    path.reverse()
    for dir in path:
        sys.path.insert(0, dir)

    # Add any product directories not already in Products.__path__.
    # Directories are added in the order they are mentioned

    instanceprod = os.path.join(config.instancehome, 'Products')
    if instanceprod not in config.products:
        if os.path.isdir(instanceprod):
            config.products.append(instanceprod)

    import Products
    L = []
    for d in config.products + Products.__path__:
        if d not in L:
            L.append(d)
    Products.__path__[:] = L

    # Augment the set of MIME types:
    if config.mime_types:
        from zope.contenttype import add_files
        add_files(config.mime_types)

    # if no servers are defined, create default http server and ftp server
    if not config.servers:
        config.servers = []

    # prepare servers:
    for factory in config.servers:
        factory.prepare(config.ip_address or '',
                        config.dns_resolver,
                        "Zope2",
                        config.cgi_environment,
                        config.port_base)

    # set up trusted proxies
    if config.trusted_proxies:
        from ZPublisher import HTTPRequest
        from ZServer.medusa import http_server
        # DM 2004-11-24: added host name mapping (such that examples in
        # conf file really have a chance to work
        mapped = []
        for name in config.trusted_proxies: mapped.extend(_name2Ips(name))
        HTTPRequest.trusted_proxies = tuple(mapped)
        http_server.trusted_proxies = tuple(mapped)
    
    # set the maximum number of ConflictError retries
    if config.max_conflict_retries:
        from ZPublisher import HTTPRequest
        HTTPRequest.retry_max_count = config.max_conflict_retries
示例#10
0
def root_handler(config):
    """ Mutate the configuration with defaults and perform
    fixups of values that require knowledge about configuration
    values outside of their context.
    """

    # Set environment variables
    for k, v in config.environment.items():
        os.environ[k] = v

    # Add directories to the pythonpath
    instancelib = os.path.join(config.instancehome, 'lib', 'python')
    if instancelib not in config.path:
        if os.path.isdir(instancelib):
            config.path.append(instancelib)
    path = config.path[:]
    path.reverse()
    for dir in path:
        sys.path.insert(0, dir)

    # Add any product directories not already in Products.__path__.
    # Directories are added in the order they are mentioned

    instanceprod = os.path.join(config.instancehome, 'Products')
    if instanceprod not in config.products:
        if os.path.isdir(instanceprod):
            config.products.append(instanceprod)

    import Products
    L = []
    for d in config.products + Products.__path__:
        if d not in L:
            L.append(d)
    Products.__path__[:] = L

    # Augment the set of MIME types:
    if config.mime_types:
        from zope.contenttype import add_files
        add_files(config.mime_types)

    # if no servers are defined, create default http server and ftp server
    if not config.servers:
        config.servers = []

    # prepare servers:
    for factory in config.servers:
        factory.prepare(config.ip_address or '', config.dns_resolver, "Zope2",
                        config.cgi_environment, config.port_base)

    # set up trusted proxies
    if config.trusted_proxies:
        from ZPublisher import HTTPRequest
        from ZServer.medusa import http_server
        # DM 2004-11-24: added host name mapping (such that examples in
        # conf file really have a chance to work
        mapped = []
        for name in config.trusted_proxies:
            mapped.extend(_name2Ips(name))
        HTTPRequest.trusted_proxies = tuple(mapped)
        http_server.trusted_proxies = tuple(mapped)

    # set the maximum number of ConflictError retries
    if config.max_conflict_retries:
        from ZPublisher import HTTPRequest
        HTTPRequest.retry_max_count = config.max_conflict_retries
示例#11
0
def root_handler(config):
    """ Mutate the configuration with defaults and perform
    fixups of values that require knowledge about configuration
    values outside of their context.
    """

    # Set environment variables
    for k,v in config.environment.items():
        os.environ[k] = v

    # Add directories to the pythonpath; always insert instancehome/lib/python
    instancelib = os.path.join(config.instancehome, 'lib', 'python')
    if instancelib not in config.path:
        config.path.append(instancelib)
    path = config.path[:]
    path.reverse()
    for dir in path:
        sys.path.insert(0, dir)

    # Add any product directories not already in Products.__path__.
    # Directories are added in the order they are mentioned
    # Always insert instancehome.Products

    instanceprod = os.path.join(config.instancehome, 'Products')
    if instanceprod not in config.products:
        config.products.append(instanceprod)

    import Products
    L = []
    for d in config.products + Products.__path__:
        if d not in L:
            L.append(d)
    Products.__path__[:] = L

    # Augment the set of MIME types:
    if config.mime_types:
        from zope.contenttype import add_files
        add_files(config.mime_types)

    # if no servers are defined, create default http server and ftp server
    if not config.servers:
        config.servers = []

    # prepare servers:
    for factory in config.servers:
        factory.prepare(config.ip_address or '',
                        config.dns_resolver,
                        "Zope2",
                        config.cgi_environment,
                        config.port_base)

    if not config.twisted_servers:
        config.twisted_servers = []
    else:
        # Set number of threads (reuse zserver_threads variable)
        twisted.internet.reactor.suggestThreadPoolSize(config.zserver_threads)

        # Create a root service
        rootService = MultiService()

        for server in config.twisted_servers:
            service = server.create(None)
            service.setServiceParent(rootService)

        rootService.startService()
        twisted.internet.reactor.addSystemEventTrigger(
            'before', 'shutdown', rootService.stopService)

    # set up trusted proxies
    if config.trusted_proxies:
        import ZPublisher.HTTPRequest
        # DM 2004-11-24: added host name mapping (such that examples in
        # conf file really have a chance to work
        mapped = []
        for name in config.trusted_proxies: mapped.extend(_name2Ips(name))
        ZPublisher.HTTPRequest.trusted_proxies = tuple(mapped)