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


Python cStringIO.OutputType方法代码示例

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


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

示例1: unpickleStringO

# 需要导入模块: import cStringIO [as 别名]
# 或者: from cStringIO import OutputType [as 别名]
def unpickleStringO(val, sek):
    """
    Convert the output of L{pickleStringO} into an appropriate type for the
    current python version.  This may be called on Python 3 and will convert a
    cStringIO into an L{io.StringIO}.

    @param val: The content of the file.
    @type val: L{bytes}

    @param sek: The seek position of the file.
    @type sek: L{int}

    @return: a file-like object which you can write bytes to.
    @rtype: L{cStringIO.OutputType} on Python 2, L{io.StringIO} on Python 3.
    """
    x = _cStringIO()
    x.write(val)
    x.seek(sek)
    return x 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:styles.py

示例2: unpickleStringI

# 需要导入模块: import cStringIO [as 别名]
# 或者: from cStringIO import OutputType [as 别名]
def unpickleStringI(val, sek):
    """
    Convert the output of L{pickleStringI} into an appropriate type for the
    current Python version.

    This may be called on Python 3 and will convert a cStringIO into an
    L{io.StringIO}.

    @param val: The content of the file.
    @type val: L{bytes}

    @param sek: The seek position of the file.
    @type sek: L{int}

    @return: a file-like object which you can read bytes from.
    @rtype: L{cStringIO.OutputType} on Python 2, L{io.StringIO} on Python 3.
    """
    x = _cStringIO(val)
    x.seek(sek)
    return x 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:styles.py

示例3: Pull

# 需要导入模块: import cStringIO [as 别名]
# 或者: from cStringIO import OutputType [as 别名]
def Pull(self, device_filename, dest_file=None, timeout_ms=None):
    """Pull a file from the device.

    Arguments:
      device_filename: The filename on the device to pull.
      dest_file: If set, a filename or writable file-like object.
      timeout_ms: Expected timeout for any part of the pull.

    Returns:
      The file data if dest_file is not set.
    """
    if isinstance(dest_file, basestring):
      dest_file = open(dest_file, 'w')
    elif not dest_file:
      dest_file = cStringIO.StringIO()
    connection = self.conn.Open(
        destination='sync:', timeout_ms=timeout_ms)
    filesync_protocol.FilesyncProtocol.Pull(
        connection, device_filename, dest_file)
    connection.Close()
    # An empty call to cStringIO.StringIO returns an instance of
    # cStringIO.OutputType.
    if isinstance(dest_file, cStringIO.OutputType):
      return dest_file.getvalue() 
开发者ID:luci,项目名称:luci-py,代码行数:26,代码来源:adb_commands.py

示例4: pickleStringO

# 需要导入模块: import cStringIO [as 别名]
# 或者: from cStringIO import OutputType [as 别名]
def pickleStringO(stringo):
    """
    Reduce the given cStringO.

    This is only called on Python 2, because the cStringIO module only exists
    on Python 2.

    @param stringo: The string output to pickle.
    @type stringo: L{cStringIO.OutputType}
    """
    'support function for copy_reg to pickle StringIO.OutputTypes'
    return unpickleStringO, (stringo.getvalue(), stringo.tell()) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:14,代码来源:styles.py

示例5: determine_how_to_feed_output

# 需要导入模块: import cStringIO [as 别名]
# 或者: from cStringIO import OutputType [as 别名]
def determine_how_to_feed_output(handler, encoding, decode_errors):
    if callable(handler):
        process, finish = get_callback_chunk_consumer(handler, encoding,
                decode_errors)

    # in py3, this is used for bytes
    elif isinstance(handler, (cStringIO, iocStringIO)):
        process, finish = get_cstringio_chunk_consumer(handler)

    # in py3, this is used for unicode
    elif isinstance(handler, (StringIO, ioStringIO)):
        process, finish = get_stringio_chunk_consumer(handler, encoding,
                decode_errors)

    elif hasattr(handler, "write"):
        process, finish = get_file_chunk_consumer(handler)

    else:
        try:
            handler = int(handler)
        except (ValueError, TypeError):
            process = lambda chunk: False
            finish = lambda: None
        else:
            process, finish = get_fd_chunk_consumer(handler)

    return process, finish 
开发者ID:acaceres2176,项目名称:scylla,代码行数:29,代码来源:sh.py

示例6: addMessage

# 需要导入模块: import cStringIO [as 别名]
# 或者: from cStringIO import OutputType [as 别名]
def addMessage(self, message, flags, date=None):
        """
        Adds a message to this mailbox.

        :param message: the raw message
        :type message: str

        :param flags: flag list
        :type flags: list of str

        :param date: timestamp
        :type date: str, or None

        :return: a deferred that will be triggered with the UID of the added
                 message.
        """
        # TODO should raise ReadOnlyMailbox if not rw.
        # TODO have a look at the cases for internal date in the rfc
        # XXX we could treat the message as an IMessage from here

        # TODO -- fast appends should be definitely solved by Blobs.
        # A better solution will probably involve implementing MULTIAPPEND
        # extension or patching imap server to support pipelining.

        if isinstance(message,
                      (cStringIO.OutputType, StringIO.StringIO, io.BytesIO)):
            message = message.getvalue()

        leap_assert_type(message, basestring)

        if flags is None:
            flags = tuple()
        else:
            flags = tuple(str(flag) for flag in flags)

        if date is None:
            date = formatdate(time.time())

        d = self.collection.add_msg(message, flags, date=date)
        d.addCallback(lambda message: message.get_uid())
        d.addErrback(
            lambda failure: self.log.failure('Error while adding msg'))
        return d 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:45,代码来源:mailbox.py

示例7: ioType

# 需要导入模块: import cStringIO [as 别名]
# 或者: from cStringIO import OutputType [as 别名]
def ioType(fileIshObject, default=unicode):
    """
    Determine the type which will be returned from the given file object's
    read() and accepted by its write() method as an argument.

    In other words, determine whether the given file is 'opened in text mode'.

    @param fileIshObject: Any object, but ideally one which resembles a file.
    @type fileIshObject: L{object}

    @param default: A default value to return when the type of C{fileIshObject}
        cannot be determined.
    @type default: L{type}

    @return: There are 3 possible return values:

            1. L{unicode}, if the file is unambiguously opened in text mode.

            2. L{bytes}, if the file is unambiguously opened in binary mode.

            3. L{basestring}, if we are on python 2 (the L{basestring} type
               does not exist on python 3) and the file is opened in binary
               mode, but has an encoding and can therefore accept both bytes
               and text reliably for writing, but will return L{bytes} from
               read methods.

            4. The C{default} parameter, if the given type is not understood.

    @rtype: L{type}
    """
    if isinstance(fileIshObject, TextIOBase):
        # If it's for text I/O, then it's for text I/O.
        return unicode
    if isinstance(fileIshObject, IOBase):
        # If it's for I/O but it's _not_ for text I/O, it's for bytes I/O.
        return bytes
    encoding = getattr(fileIshObject, 'encoding', None)
    import codecs
    if isinstance(fileIshObject, (codecs.StreamReader, codecs.StreamWriter)):
        # On StreamReaderWriter, the 'encoding' attribute has special meaning;
        # it is unambiguously unicode.
        if encoding:
            return unicode
        else:
            return bytes
    if not _PY3:
        # Special case: if we have an encoding file, we can *give* it unicode,
        # but we can't expect to *get* unicode.
        if isinstance(fileIshObject, file):
            if encoding is not None:
                return basestring
            else:
                return bytes
        from cStringIO import InputType, OutputType
        from StringIO import StringIO
        if isinstance(fileIshObject, (StringIO, InputType, OutputType)):
            return bytes
    return default 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:60,代码来源:compat.py


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