當前位置: 首頁>>代碼示例>>Python>>正文


Python _os.safe_join方法代碼示例

本文整理匯總了Python中django.utils._os.safe_join方法的典型用法代碼示例。如果您正苦於以下問題:Python _os.safe_join方法的具體用法?Python _os.safe_join怎麽用?Python _os.safe_join使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.utils._os的用法示例。


在下文中一共展示了_os.safe_join方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_template_sources

# 需要導入模塊: from django.utils import _os [as 別名]
# 或者: from django.utils._os import safe_join [as 別名]
def get_template_sources(self, template_name):
        """
        Return an Origin object pointing to an absolute path in each directory
        in template_dirs. For security reasons, if a path doesn't lie inside
        one of the template_dirs it is excluded from the result set.
        """
        for template_dir in self.get_dirs():
            try:
                name = safe_join(template_dir, template_name)
            except SuspiciousFileOperation:
                # The joined path was located outside of this template_dir
                # (it might be inside another one, so this isn't fatal).
                continue

            yield Origin(
                name=name,
                template_name=template_name,
                loader=self,
            ) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:21,代碼來源:filesystem.py

示例2: get_template_sources

# 需要導入模塊: from django.utils import _os [as 別名]
# 或者: from django.utils._os import safe_join [as 別名]
def get_template_sources(self, template_name, template_dirs=None):
        """
        Return an Origin object pointing to an absolute path in each directory
        in template_dirs. For security reasons, if a path doesn't lie inside
        one of the template_dirs it is excluded from the result set.
        """
        if not template_dirs:
            template_dirs = self.get_dirs()
        for template_dir in template_dirs:
            try:
                name = safe_join(template_dir, template_name)
            except SuspiciousFileOperation:
                # The joined path was located outside of this template_dir
                # (it might be inside another one, so this isn't fatal).
                continue

            yield Origin(
                name=name,
                template_name=template_name,
                loader=self,
            ) 
開發者ID:BirkbeckCTP,項目名稱:janeway,代碼行數:23,代碼來源:template_override_middleware.py

示例3: get_template_sources

# 需要導入模塊: from django.utils import _os [as 別名]
# 或者: from django.utils._os import safe_join [as 別名]
def get_template_sources(self, template_name, template_dirs=None):
        """
        Returns the absolute paths to "template_name", when appended to each
        directory in "template_dirs". Any paths that don't lie inside one of the
        template dirs are excluded from the result set, for security reasons.
        """
        if not template_dirs:
            template_dirs = app_template_dirs
        for template_dir in template_dirs:
            try:
                yield safe_join(template_dir, template_name)
            except UnicodeDecodeError:
                # The template dir name was a bytestring that wasn't valid UTF-8.
                raise
            except ValueError:
                # The joined path was located outside of template_dir.
                pass 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:19,代碼來源:app_directories.py

示例4: get_template_sources

# 需要導入模塊: from django.utils import _os [as 別名]
# 或者: from django.utils._os import safe_join [as 別名]
def get_template_sources(self, template_name, template_dirs=None):
        """
        Returns the absolute paths to "template_name", when appended to each
        directory in "template_dirs". Any paths that don't lie inside one of the
        template dirs are excluded from the result set, for security reasons.
        """
        if not template_dirs:
            template_dirs = settings.TEMPLATE_DIRS
        for template_dir in template_dirs:
            try:
                yield safe_join(template_dir, template_name)
            except UnicodeDecodeError:
                # The template dir name was a bytestring that wasn't valid UTF-8.
                raise
            except ValueError:
                # The joined path was located outside of this particular
                # template_dir (it might be inside another one, so this isn't
                # fatal).
                pass 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:21,代碼來源:filesystem.py

示例5: get_template_sources

# 需要導入模塊: from django.utils import _os [as 別名]
# 或者: from django.utils._os import safe_join [as 別名]
def get_template_sources(self, template_name, template_dirs=None):
        """
        Return an Origin object pointing to an absolute path in each directory
        in template_dirs. For security reasons, if a path doesn't lie inside
        one of the template_dirs it is excluded from the result set.
        """
        if not template_dirs:
            template_dirs = get_directories_in_tethys(('templates',))
        for template_dir in template_dirs:
            try:
                name = safe_join(template_dir, template_name)
            except SuspiciousFileOperation:
                # The joined path was located outside of this template_dir
                # (it might be inside another one, so this isn't fatal).
                continue

            yield Origin(
                name=name,
                template_name=template_name,
                loader=self,
            ) 
開發者ID:tethysplatform,項目名稱:tethys,代碼行數:23,代碼來源:template_loaders.py

示例6: iter_template_filenames

# 需要導入模塊: from django.utils import _os [as 別名]
# 或者: from django.utils._os import safe_join [as 別名]
def iter_template_filenames(self, template_name):
        """
        Iterates over candidate files for template_name.

        Ignores files that don't lie inside configured template dirs to avoid
        directory traversal attacks.
        """
        for template_dir in self.template_dirs:
            try:
                yield safe_join(template_dir, template_name)
            except SuspiciousFileOperation:
                # The joined path was located outside of this template_dir
                # (it might be inside another one, so this isn't fatal).
                pass 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:16,代碼來源:base.py

示例7: get_template_sources

# 需要導入模塊: from django.utils import _os [as 別名]
# 或者: from django.utils._os import safe_join [as 別名]
def get_template_sources(self, template_name, template_dirs=None):
        """
        Returns the absolute paths to "template_name", when appended to each
        directory in "template_dirs". Any paths that don't lie inside one of the
        template dirs are excluded from the result set, for security reasons.
        """
        if not template_dirs:
            template_dirs = get_app_template_dirs('templates')
        for template_dir in template_dirs:
            try:
                yield safe_join(template_dir, template_name)
            except SuspiciousFileOperation:
                # The joined path was located outside of this template_dir
                # (it might be inside another one, so this isn't fatal).
                pass 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:17,代碼來源:app_directories.py

示例8: get_template_sources

# 需要導入模塊: from django.utils import _os [as 別名]
# 或者: from django.utils._os import safe_join [as 別名]
def get_template_sources(self, template_name, template_dirs=None):
        """
        Returns the absolute paths to "template_name", when appended to each
        directory in "template_dirs". Any paths that don't lie inside one of the
        template dirs are excluded from the result set, for security reasons.
        """
        if not template_dirs:
            template_dirs = self.engine.dirs
        for template_dir in template_dirs:
            try:
                yield safe_join(template_dir, template_name)
            except SuspiciousFileOperation:
                # The joined path was located outside of this template_dir
                # (it might be inside another one, so this isn't fatal).
                pass 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:17,代碼來源:filesystem.py

示例9: find_location

# 需要導入模塊: from django.utils import _os [as 別名]
# 或者: from django.utils._os import safe_join [as 別名]
def find_location(self, root, path, prefix=None):
        """
        Finds a requested static file in a location, returning the found
        absolute path (or ``None`` if no match).
        """
        if prefix:
            prefix = '%s%s' % (prefix, os.sep)
            if not path.startswith(prefix):
                return None
            path = path[len(prefix):]
        path = safe_join(root, path)
        if os.path.exists(path):
            return path 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:15,代碼來源:finders.py

示例10: path

# 需要導入模塊: from django.utils import _os [as 別名]
# 或者: from django.utils._os import safe_join [as 別名]
def path(self, name):
        return safe_join(self.location, name) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:4,代碼來源:storage.py

示例11: serve

# 需要導入模塊: from django.utils import _os [as 別名]
# 或者: from django.utils._os import safe_join [as 別名]
def serve(request, path, document_root=None, show_indexes=False):
    """
    Serve static files below a given point in the directory structure.

    To use, put a URL pattern such as::

        from django.views.static import serve

        url(r'^(?P<path>.*)$', serve, {'document_root': '/path/to/my/files/'})

    in your URLconf. You must provide the ``document_root`` param. You may
    also set ``show_indexes`` to ``True`` if you'd like to serve a basic index
    of the directory.  This index view will use the template hardcoded below,
    but if you'd like to override it, you can create a template called
    ``static/directory_index.html``.
    """
    path = posixpath.normpath(path).lstrip('/')
    fullpath = safe_join(document_root, path)
    if os.path.isdir(fullpath):
        if show_indexes:
            return directory_index(path, fullpath)
        raise Http404(_("Directory indexes are not allowed here."))
    if not os.path.exists(fullpath):
        raise Http404(_('"%(path)s" does not exist') % {'path': fullpath})
    # Respect the If-Modified-Since header.
    statobj = os.stat(fullpath)
    if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
                              statobj.st_mtime, statobj.st_size):
        return HttpResponseNotModified()
    content_type, encoding = mimetypes.guess_type(fullpath)
    content_type = content_type or 'application/octet-stream'
    response = FileResponse(open(fullpath, 'rb'), content_type=content_type)
    response["Last-Modified"] = http_date(statobj.st_mtime)
    if stat.S_ISREG(statobj.st_mode):
        response["Content-Length"] = statobj.st_size
    if encoding:
        response["Content-Encoding"] = encoding
    return response 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:40,代碼來源:static.py

示例12: iter_template_filenames

# 需要導入模塊: from django.utils import _os [as 別名]
# 或者: from django.utils._os import safe_join [as 別名]
def iter_template_filenames(self, template_name):
        """
        Iterate over candidate files for template_name.

        Ignore files that don't lie inside configured template dirs to avoid
        directory traversal attacks.
        """
        for template_dir in self.template_dirs:
            try:
                yield safe_join(template_dir, template_name)
            except SuspiciousFileOperation:
                # The joined path was located outside of this template_dir
                # (it might be inside another one, so this isn't fatal).
                pass 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:16,代碼來源:base.py

示例13: find_location

# 需要導入模塊: from django.utils import _os [as 別名]
# 或者: from django.utils._os import safe_join [as 別名]
def find_location(self, root, path, prefix=None):
        """
        Find a requested static file in a location and return the found
        absolute path (or ``None`` if no match).
        """
        if prefix:
            prefix = '%s%s' % (prefix, os.sep)
            if not path.startswith(prefix):
                return None
            path = path[len(prefix):]
        path = safe_join(root, path)
        if os.path.exists(path):
            return path 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:15,代碼來源:finders.py

示例14: get_template_source

# 需要導入模塊: from django.utils import _os [as 別名]
# 或者: from django.utils._os import safe_join [as 別名]
def get_template_source(name, dirs=None):
    """Retrieves the template's source contents.

    :param name: Template's filename, as passed to the template loader.
    :param dirs: list of directories to optionally override the defaults.
    :return: tuple including file contents and file path.
    """
    loaders = []
    for loader in Engine.get_default().template_loaders:
        # The cached loader includes the actual loaders underneath
        if hasattr(loader, "loaders"):
            loaders.extend(loader.loaders)
        else:
            loaders.append(loader)

    for loader in loaders:
        for template_dir in loader.get_dirs():
            try:
                filename = safe_join(template_dir, name)
            except SuspiciousFileOperation:
                # The joined path was located outside of this template_dir
                # (it might be inside another one, so this isn't fatal).
                continue

            try:
                with open(filename, encoding=loader.engine.file_charset) as fp:
                    return fp.read()
            except FileNotFoundError:
                continue

    raise TemplateDoesNotExist(name) 
開發者ID:evernote,項目名稱:zing,代碼行數:33,代碼來源:templates.py

示例15: serve

# 需要導入模塊: from django.utils import _os [as 別名]
# 或者: from django.utils._os import safe_join [as 別名]
def serve(request, path, document_root=None, show_indexes=False):
    """
    Serve static files below a given point in the directory structure.

    To use, put a URL pattern such as::

        from django.views.static import serve

        url(r'^(?P<path>.*)$', serve, {'document_root': '/path/to/my/files/'})

    in your URLconf. You must provide the ``document_root`` param. You may
    also set ``show_indexes`` to ``True`` if you'd like to serve a basic index
    of the directory.  This index view will use the template hardcoded below,
    but if you'd like to override it, you can create a template called
    ``static/directory_index.html``.
    """
    path = posixpath.normpath(path).lstrip('/')
    fullpath = Path(safe_join(document_root, path))
    if fullpath.is_dir():
        if show_indexes:
            return directory_index(path, fullpath)
        raise Http404(_("Directory indexes are not allowed here."))
    if not fullpath.exists():
        raise Http404(_('"%(path)s" does not exist') % {'path': fullpath})
    # Respect the If-Modified-Since header.
    statobj = fullpath.stat()
    if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
                              statobj.st_mtime, statobj.st_size):
        return HttpResponseNotModified()
    content_type, encoding = mimetypes.guess_type(str(fullpath))
    content_type = content_type or 'application/octet-stream'
    response = FileResponse(fullpath.open('rb'), content_type=content_type)
    response["Last-Modified"] = http_date(statobj.st_mtime)
    if encoding:
        response["Content-Encoding"] = encoding
    return response 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:38,代碼來源:static.py


注:本文中的django.utils._os.safe_join方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。