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


Python mimetypes.init方法代码示例

本文整理汇总了Python中mimetypes.init方法的典型用法代码示例。如果您正苦于以下问题:Python mimetypes.init方法的具体用法?Python mimetypes.init怎么用?Python mimetypes.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mimetypes的用法示例。


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

示例1: test_non_latin_extension

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import init [as 别名]
def test_non_latin_extension(self):
        import _winreg

        class MockWinreg(object):
            def __getattr__(self, name):
                if name == 'EnumKey':
                    return lambda key, i: _winreg.EnumKey(key, i) + "\xa3"
                elif name == 'OpenKey':
                    return lambda key, name: _winreg.OpenKey(key, name.rstrip("\xa3"))
                elif name == 'QueryValueEx':
                    return lambda subkey, label: (u'текст/простой' , _winreg.REG_SZ)
                return getattr(_winreg, name)

        mimetypes._winreg = MockWinreg()
        try:
            # this used to throw an exception if registry contained non-Latin
            # characters in extensions (issue #9291)
            mimetypes.init()
        finally:
            mimetypes._winreg = _winreg 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_mimetypes.py

示例2: test_non_latin_type

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import init [as 别名]
def test_non_latin_type(self):
        import _winreg

        class MockWinreg(object):
            def __getattr__(self, name):
                if name == 'QueryValueEx':
                    return lambda subkey, label: (u'текст/простой', _winreg.REG_SZ)
                return getattr(_winreg, name)

        mimetypes._winreg = MockWinreg()
        try:
            # this used to throw an exception if registry contained non-Latin
            # characters in content types (issue #9291)
            mimetypes.init()
        finally:
            mimetypes._winreg = _winreg 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_mimetypes.py

示例3: test_registry_read_error

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import init [as 别名]
def test_registry_read_error(self):
        import _winreg

        class MockWinreg(object):
            def OpenKey(self, key, name):
                if key != _winreg.HKEY_CLASSES_ROOT:
                    raise WindowsError(5, "Access is denied")
                return _winreg.OpenKey(key, name)
            def __getattr__(self, name):
                return getattr(_winreg, name)

        mimetypes._winreg = MockWinreg()
        try:
            mimetypes.init()
        finally:
            mimetypes._winreg = _winreg 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_mimetypes.py

示例4: fileDir

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import init [as 别名]
def fileDir(dirInput, recursive):
    if os.path.isdir(dirInput):
        print "Scraping Files in Local Directory {0}- {1}".format('(recursively) ' if recursive else '', dirInput)
        mimetypes.init()
        fileTypes = ('*.conf', '*.cs', '*.js', '*.c', '*.cpp', '*.c++', '*.pdf', '*.docx', '*.txt', '*.csv', '*.py', '*.cpp', '*.pl', '*.log', '*.rtf', '*.css', '*.dat', '*.html', '*.php', '*.pps', '*.ppt', '*.pptx', '*.sh', '*.xml', '*.xsl')
        if recursive:
            for root, dirs, files in os.walk(dirInput):
                for fileType in fileTypes:
                    for file_name in fnmatch.filter(files, fileType):
                        file_path = os.path.join(root, file_name)
                        file_type, file_encoding = mimetypes.guess_type(file_path)
                        localFile(file_path)
        else:
            for fileType in fileTypes:
                for globFile in glob.glob(os.path.join(dirInput, fileType)):
                    file_type, file_encoding = mimetypes.guess_type(globFile)
                    localFile(globFile)
    else:
        print 'Error accessing directory: {0}'.format(dirInput) 
开发者ID:SmeegeSec,项目名称:SmeegeScrape,代码行数:21,代码来源:SmeegeScrape.py

示例5: distribute

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import init [as 别名]
def distribute(self, filepath, allow_folders=True):
        self._checkpath(filepath)
        path = os.path.abspath(os.path.join(self.prefix, filepath))
        if not os.path.exists(path):
            return ("invalid", None, None)
        if os.path.isdir(path):
            if not allow_folders:
                return ("invalid", None, None)
            zipf = zipstream.ZipFile()
            for root, _, files in os.walk(path):
                for filename in files:
                    file_path = os.path.join(root, filename)
                    arcpath = os.path.relpath(file_path, path)
                    zipf.write(file_path, arcpath)
            return ("local", "application/zip", zipf.__iter__()) #the __iter__ is only present to fix a bug in web.py for py3; it only recognizes
                                                                 #iterable that possess a __next__. ZipFile.__iter__ returns an iterable in the web.py
                                                                 #sense
        elif os.path.isfile(path):
            mimetypes.init()
            mime_type = mimetypes.guess_type(path)
            return ("local", mime_type[0], open(path, 'rb')) 
开发者ID:UCL-INGI,项目名称:INGInious,代码行数:23,代码来源:local.py

示例6: getFileExtensions

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import init [as 别名]
def getFileExtensions(mime):
    if(not mimetypes.inited):
        mimetypes.init()
        initKnowMimetypes()

    types = mime.split(";")

    result = []

    for t in types:
        if(t):
            res = mimetypes.guess_all_extensions(t)
            #print("getting extensions for mime " + str(t) + " " + str(res))
            result.extend(res)

    if(len(result) == 0):
        result.append(".*")
        
    return result 
开发者ID:JackD83,项目名称:PyMenu,代码行数:21,代码来源:OPKHelper.py

示例7: problem_init_view

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import init [as 别名]
def problem_init_view(request, problem):
    problem = get_object_or_404(Problem, code=problem)
    if not problem.is_editable_by(request.user):
        raise Http404()

    try:
        with problem_data_storage.open(os.path.join(problem.code, 'init.yml'), 'rb') as f:
            data = utf8text(f.read()).rstrip('\n')
    except IOError:
        raise Http404()

    return render(request, 'problem/yaml.html', {
        'raw_source': data, 'highlighted_source': highlight_code(data, 'yaml'),
        'title': _('Generated init.yml for %s') % problem.name,
        'content_title': mark_safe(escape(_('Generated init.yml for %s')) % (
            format_html('<a href="{1}">{0}</a>', problem.name,
                        reverse('problem_detail', args=[problem.code])))),
    }) 
开发者ID:DMOJ,项目名称:online-judge,代码行数:20,代码来源:problem_data.py

示例8: init

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import init [as 别名]
def init(self):
        with flx.HBox():
            self.leaflet = LeafletWidget(
                flex=1,
                center=(52, 4.1),
                zoom=12,
                show_scale=lambda: self.cbs.checked,
                show_layers=lambda: self.cbl.checked,
            )
            with flx.VBox():
                self.btna = flx.Button(text='Add SeaMap')
                self.btnr = flx.Button(text='Remove SeaMap')
                self.cbs = flx.CheckBox(text='Show scale')
                self.cbl = flx.CheckBox(text='Show layers')
                self.list = flx.VBox()
                flx.Widget(flex=1)

        self.leaflet.add_layer('http://a.tile.openstreetmap.org/', 'OpenStreetMap') 
开发者ID:flexxui,项目名称:flexx,代码行数:20,代码来源:leaflet.py

示例9: upload_fake_file

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import init [as 别名]
def upload_fake_file():
    if not request.files:
        return "", 401

    if not mimetypes.inited:
        mimetypes.init()

    for key, item in request.files.items():
        if item.filename:
            filetype = ".{}".format(item.filename.split(".")[-1])
            if filetype in mimetypes.suffix_map:
                if not item.content_type:
                    return "", 400

    # Try to download each of the files downloaded to /tmp and
    # then remove them
    for key in request.files:
        file_to_save = request.files[key]
        path = os.path.join("/tmp", file_to_save.filename)
        file_to_save.save(path)

    return "", 200 
开发者ID:taverntesting,项目名称:tavern,代码行数:24,代码来源:server.py

示例10: load_project

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import init [as 别名]
def load_project(path=None):
    """
    Read project from directory passed as the argument and return Project
    object. If no argument is given, the project is read from the current
    directory.
    """
    if not path:
        p = os.getcwd()
    else:
        p = os.path.abspath(path)
    while not os.path.isdir(os.path.join(p, ".smt")):
        oldp, p = p, os.path.dirname(p)
        if p == oldp:
            raise IOError("No Sumatra project exists in the current directory or above it.")
    mimetypes.init(mimetypes.knownfiles + [os.path.join(p, ".smt", "mime.types")])
    # try:
    prj = _load_project_from_json(p)
    # except Exception:
    #    prj = _load_project_from_pickle(p)
    return prj 
开发者ID:open-research,项目名称:sumatra,代码行数:22,代码来源:projects.py

示例11: _setup_mimetypes

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import init [as 别名]
def _setup_mimetypes():
    """Pre-initialize global mimetype map."""
    if not mimetypes.inited:
        mimetypes.init()
    mimetypes.types_map['.dwg'] = 'image/x-dwg'
    mimetypes.types_map['.ico'] = 'image/x-icon'
    mimetypes.types_map['.bz2'] = 'application/x-bzip2'
    mimetypes.types_map['.gz'] = 'application/x-gzip' 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:10,代码来源:static.py

示例12: get_file

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import init [as 别名]
def get_file(request, path):
    """
    Returns a file from the upload directory
    """
    try:
        f = open(os.path.join(settings.MEDIA_ROOT, path), 'r')
    except IOError:
        raise Http404
    
    mimetypes.init()
    t, e = mimetypes.guess_type(f.name)

    return HttpResponse(f.read(), t) 
开发者ID:fpsw,项目名称:Servo,代码行数:15,代码来源:files.py

示例13: test_registry_parsing

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import init [as 别名]
def test_registry_parsing(self):
        # the original, minimum contents of the MIME database in the
        # Windows registry is undocumented AFAIK.
        # Use file types that should *always* exist:
        eq = self.assertEqual
        mimetypes.init()
        db = mimetypes.MimeTypes()
        eq(db.guess_type("foo.txt"), ("text/plain", None))
        eq(db.guess_type("image.jpg"), ("image/jpeg", None))
        eq(db.guess_type("image.png"), ("image/png", None)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_mimetypes.py

示例14: test_type_map_values

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import init [as 别名]
def test_type_map_values(self):
        import _winreg

        class MockWinreg(object):
            def __getattr__(self, name):
                if name == 'QueryValueEx':
                    return lambda subkey, label: (u'text/plain', _winreg.REG_SZ)
                return getattr(_winreg, name)

        mimetypes._winreg = MockWinreg()
        try:
            mimetypes.init()
            self.assertTrue(isinstance(mimetypes.types_map.values()[0], str))
        finally:
            mimetypes._winreg = _winreg 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:test_mimetypes.py

示例15: guess_mime_type

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import init [as 别名]
def guess_mime_type(filename):
  """Guess mime type based of file extension."""
  if not mimetypes.inited:
    mimetypes.init()

  return mimetypes.guess_type(filename)[0] 
开发者ID:google,项目名称:clusterfuzz,代码行数:8,代码来源:http_server.py


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