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


Python cStringIO.close方法代碼示例

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


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

示例1: render_markdown_from_file

# 需要導入模塊: from django.utils.six.moves import cStringIO [as 別名]
# 或者: from django.utils.six.moves.cStringIO import close [as 別名]
def render_markdown_from_file(f, **markdown_kwargs):
    """Render Markdown text from a file stream to HTML."""
    s = StringIO()
    markdownFromFile(input=f, output=s, **markdown_kwargs)
    html = s.getvalue()
    s.close()

    return html
開發者ID:chipx86,項目名稱:djblets,代碼行數:10,代碼來源:__init__.py

示例2: render_markdown_from_file

# 需要導入模塊: from django.utils.six.moves import cStringIO [as 別名]
# 或者: from django.utils.six.moves.cStringIO import close [as 別名]
def render_markdown_from_file(f):
    """Renders Markdown text to HTML.

    The Markdown text will be sanitized to prevent injecting custom HTML.
    It will also enable a few plugins for code highlighting and sane lists.
    """
    s = StringIO()
    markdownFromFile(input=f, output=s, **MARKDOWN_KWARGS)
    html = s.getvalue()
    s.close()

    return html
開發者ID:aaronmartin0303,項目名稱:reviewboard,代碼行數:14,代碼來源:markdown_utils.py

示例3: _migrate_extension_models

# 需要導入模塊: from django.utils.six.moves import cStringIO [as 別名]
# 或者: from django.utils.six.moves.cStringIO import close [as 別名]
    def _migrate_extension_models(self, ext_class):
        """Perform database migrations for an extension's models.

        This will call out to Django Evolution to handle the migrations.

        Args:
            ext_class (djblets.extensions.extension.Extension):
                The class for the extension to migrate.
        """
        try:
            from django_evolution.management.commands.evolve import \
                Command as Evolution
        except ImportError:
            raise InstallExtensionError(
                "Unable to migrate the extension's database tables. Django "
                "Evolution is not installed.")

        try:
            stream = StringIO()
            evolution = Evolution()
            evolution.style = no_style()
            evolution.execute(verbosity=0, interactive=False,
                              execute=True, hint=False,
                              compile_sql=False, purge=False,
                              database=False,
                              stdout=stream, stderr=stream)

            output = stream.getvalue()

            if output:
                logging.info('Evolved extension models for %s: %s',
                             ext_class.id, stream.read())

            stream.close()
        except CommandError as e:
            # Something went wrong while running django-evolution, so
            # grab the output.  We can't raise right away because we
            # still need to put stdout back the way it was
            output = stream.getvalue()
            stream.close()

            logging.error('Error evolving extension models: %s: %s',
                          e, output, exc_info=1)

            load_error = self._store_load_error(ext_class.id, output)
            raise InstallExtensionError(six.text_type(e), load_error)
開發者ID:thanatrakul,項目名稱:djblets,代碼行數:48,代碼來源:manager.py

示例4: _migrate_extension_models

# 需要導入模塊: from django.utils.six.moves import cStringIO [as 別名]
# 或者: from django.utils.six.moves.cStringIO import close [as 別名]
    def _migrate_extension_models(self, ext_class):
        """Perform database migrations for an extension's models.

        This will call out to Django Evolution to handle the migrations.

        Args:
            ext_class (djblets.extensions.extension.Extension):
                The class for the extension to migrate.
        """
        if django_evolution is None:
            # Django Evolution isn't installed. Extensions with evolutions
            # are not supported.
            return

        try:
            stream = StringIO()
            call_command('evolve',
                         verbosity=0,
                         interactive=False,
                         execute=True,
                         stdout=stream,
                         stderr=stream)
            output = stream.getvalue()

            if output:
                logger.info('Evolved extension models for %s: %s',
                            ext_class.id, stream.read())

            stream.close()
        except CommandError as e:
            # Something went wrong while running django-evolution, so
            # grab the output.  We can't raise right away because we
            # still need to put stdout back the way it was
            output = stream.getvalue()
            stream.close()

            logger.exception('Error evolving extension models: %s: %s',
                             e, output)

            load_error = self._store_load_error(ext_class.id, output)
            raise InstallExtensionError(six.text_type(e), load_error)
開發者ID:davidt,項目名稱:djblets,代碼行數:43,代碼來源:manager.py

示例5: FileStream

# 需要導入模塊: from django.utils.six.moves import cStringIO [as 別名]
# 或者: from django.utils.six.moves.cStringIO import close [as 別名]
class FileStream(object):
    """File stream for streaming reponses

    This buffer intended for use as an argument to StreamingHTTPResponse
    and also as a file for TarFile to write into.

    Files are read in by chunks and written to this buffer through TarFile.
    When there is content to be read from the buffer, it is taken up by
    StreamingHTTPResponse and the buffer is cleared to prevent storing large
    chunks of data in memory.
    """
    def __init__(self):
        self.buffer = StringIO()
        self.offset = 0

    def write(self, s):
        """Write ``s`` to the buffer and adjust the offset."""
        self.buffer.write(s)
        self.offset += len(s)

    def tell(self):
        """Return the current position of the buffer."""
        return self.offset

    def close(self):
        """Close the buffer."""
        self.buffer.close()

    def pop(self):
        """Return the current contents of the buffer then clear it."""
        s = self.buffer.getvalue()
        self.buffer.close()

        self.buffer = StringIO()

        return s
開發者ID:bkawula,項目名稱:django-swiftbrowser,代碼行數:38,代碼來源:streaming_tarfile.py

示例6: parse

# 需要導入模塊: from django.utils.six.moves import cStringIO [as 別名]
# 或者: from django.utils.six.moves.cStringIO import close [as 別名]
    def parse(self):
        """
        Parses the diff, returning a list of File objects representing each
        file in the diff.
        """
        self.files = []
        i = 0
        preamble = StringIO()

        while i < len(self.lines):
            next_i, file_info, new_diff = self._parse_diff(i)

            if file_info:
                if self.files:
                    self.files[-1].finalize()

                self._ensure_file_has_required_fields(file_info)

                file_info.prepend_data(preamble.getvalue())
                preamble.close()
                preamble = StringIO()

                self.files.append(file_info)
            elif new_diff:
                # We found a diff, but it was empty and has no file entry.
                # Reset the preamble.
                preamble.close()
                preamble = StringIO()
            else:
                preamble.write(self.lines[i])
                preamble.write(b'\n')

            i = next_i

        try:
            if self.files:
                self.files[-1].finalize()
            elif preamble.getvalue().strip() != b'':
                # This is probably not an actual git diff file.
                raise DiffParserError('This does not appear to be a git diff',
                                      0)
        finally:
            preamble.close()

        return self.files
開發者ID:xiaogao6681,項目名稱:reviewboard,代碼行數:47,代碼來源:git.py

示例7: _install_extension_media_internal

# 需要導入模塊: from django.utils.six.moves import cStringIO [as 別名]
# 或者: from django.utils.six.moves.cStringIO import close [as 別名]
    def _install_extension_media_internal(self, ext_class):
        """Installs extension data.

        Performs any installation necessary for an extension.

        If the extension has a legacy htdocs/ directory for static media
        files, they will be installed into MEDIA_ROOT/ext/, and a warning
        will be logged.

        If the extension has a modern static/ directory, they will be
        installed into STATIC_ROOT/ext/.
        """
        ext_htdocs_path = ext_class.info.installed_htdocs_path
        ext_htdocs_path_exists = os.path.exists(ext_htdocs_path)

        if ext_htdocs_path_exists:
            # First, get rid of the old htdocs contents, so we can start
            # fresh.
            shutil.rmtree(ext_htdocs_path, ignore_errors=True)

        if pkg_resources.resource_exists(ext_class.__module__, 'htdocs'):
            # This is an older extension that doesn't use the static file
            # support. Log a deprecation notice and then install the files.
            logging.warning('The %s extension uses the deprecated "htdocs" '
                            'directory for static files. It should be updated '
                            'to use a "static" directory instead.'
                            % ext_class.info.name)

            extracted_path = \
                pkg_resources.resource_filename(ext_class.__module__, 'htdocs')

            shutil.copytree(extracted_path, ext_htdocs_path, symlinks=True)

        # We only want to install static media on a non-DEBUG install.
        # Otherwise, we run the risk of creating a new 'static' directory and
        # causing Django to look up all static files (not just from
        # extensions) from there instead of from their source locations.
        if not settings.DEBUG:
            ext_static_path = ext_class.info.installed_static_path
            ext_static_path_exists = os.path.exists(ext_static_path)

            if ext_static_path_exists:
                # Also get rid of the old static contents.
                shutil.rmtree(ext_static_path, ignore_errors=True)

            if pkg_resources.resource_exists(ext_class.__module__, 'static'):
                extracted_path = \
                    pkg_resources.resource_filename(ext_class.__module__,
                                                    'static')

                shutil.copytree(extracted_path, ext_static_path, symlinks=True)

        # Mark the extension as installed
        ext_class.registration.installed = True
        ext_class.registration.save()

        # Now let's build any tables that this extension might need
        self._add_to_installed_apps(ext_class)

        # Call syncdb to create the new tables
        loading.cache.loaded = False
        call_command('syncdb', verbosity=0, interactive=False)

        # Run evolve to do any table modification
        try:
            stream = StringIO()
            evolution = Evolution()
            evolution.style = no_style()
            evolution.execute(verbosity=0, interactive=False,
                              execute=True, hint=False,
                              compile_sql=False, purge=False,
                              database=False,
                              stdout=stream, stderr=stream)

            output = stream.getvalue()

            if output:
                logging.info('Evolved extension models for %s: %s',
                             ext_class.id, stream.read())

            stream.close()
        except CommandError as e:
            # Something went wrong while running django-evolution, so
            # grab the output.  We can't raise right away because we
            # still need to put stdout back the way it was
            output = stream.getvalue()
            stream.close()

            logging.error('Error evolving extension models: %s: %s',
                          e, output, exc_info=1)

            load_error = self._store_load_error(ext_class.id, output)
            raise InstallExtensionError(six.text_type(e), load_error)

        # Remove this again, since we only needed it for syncdb and
        # evolve.  _init_extension will add it again later in
        # the install.
        self._remove_from_installed_apps(ext_class)

        # Mark the extension as installed
#.........這裏部分代碼省略.........
開發者ID:halvorlu,項目名稱:djblets,代碼行數:103,代碼來源:manager.py


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