當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。