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


Python io.BufferedRandom方法代码示例

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


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

示例1: chown

# 需要导入模块: import io [as 别名]
# 或者: from io import BufferedRandom [as 别名]
def chown(path: Union[str, TextIOWrapper, BufferedRandom, BufferedRWPair, BufferedWriter, IOBase]):
    if not bench_as_different_user():
        return
    if isinstance(path, IOBase) and path.isatty():
        return
    if not isinstance(path, str):
        return chown(path.name)
    ids = ()
    try:
        ids = get_bench_uid_and_gid()
    except:
        global _logged_chown_error
        if not _logged_chown_error:
            logging.warn("Could not get user id for user {} therefore no chowning possible".format(get_bench_user()))
            _logged_chown_error = True
        return
    try:
        os.chown(path, *ids)
    except FileNotFoundError:
        pass 
开发者ID:parttimenerd,项目名称:temci,代码行数:22,代码来源:sudo_utils.py

示例2: load

# 需要导入模块: import io [as 别名]
# 或者: from io import BufferedRandom [as 别名]
def load(self, source, mode='t', encoding=None):

        # Prepare source
        scheme = 'text://'
        if source.startswith(scheme):
            source = source.replace(scheme, '', 1)

        # Prepare bytes
        bytes = io.BufferedRandom(io.BytesIO())
        bytes.write(source.encode(encoding or config.DEFAULT_ENCODING))
        bytes.seek(0)
        if self.__stats:
            bytes = helpers.BytesStatsWrapper(bytes, self.__stats)

        # Return bytes
        if mode == 'b':
            return bytes

        # Prepare chars
        chars = io.TextIOWrapper(bytes, encoding)

        return chars 
开发者ID:frictionlessdata,项目名称:tabulator-py,代码行数:24,代码来源:text.py

示例3: genfile

# 需要导入模块: import io [as 别名]
# 或者: from io import BufferedRandom [as 别名]
def genfile(*paths):
    '''
    Create or open ( for read/write ) a file path join.

    Args:
        *paths: A list of paths to join together to make the file.

    Notes:
        If the file already exists, the fd returned is opened in ``r+b`` mode.
        Otherwise, the fd is opened in ``w+b`` mode.

        The file position is set to the start of the file.  The user is
        responsible for truncating (``fd.truncate()``) if the existing file
        contents are not desired, or seeking to the end (``fd.seek(0, 2)``)
        to append.

    Returns:
        io.BufferedRandom: A file-object which can be read/written too.
    '''
    path = genpath(*paths)
    gendir(os.path.dirname(path))
    if not os.path.isfile(path):
        return io.open(path, 'w+b')
    return io.open(path, 'r+b') 
开发者ID:vertexproject,项目名称:synapse,代码行数:26,代码来源:common.py

示例4: test_unpickling_buffering_readline

# 需要导入模块: import io [as 别名]
# 或者: from io import BufferedRandom [as 别名]
def test_unpickling_buffering_readline(self):
        # Issue #12687: the unpickler's buffering logic could fail with
        # text mode opcodes.
        import io
        data = list(xrange(10))
        for proto in protocols:
            for buf_size in xrange(1, 11):
                f = io.BufferedRandom(io.BytesIO(), buffer_size=buf_size)
                pickler = self.pickler_class(f, protocol=proto)
                pickler.dump(data)
                f.seek(0)
                unpickler = self.unpickler_class(f)
                self.assertEqual(unpickler.load(), data) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:pickletester.py

示例5: test_unpickling_buffering_readline

# 需要导入模块: import io [as 别名]
# 或者: from io import BufferedRandom [as 别名]
def test_unpickling_buffering_readline(self):
        # Issue #12687: the unpickler's buffering logic could fail with
        # text mode opcodes.
        data = list(range(10))
        for proto in protocols:
            for buf_size in range(1, 11):
                f = io.BufferedRandom(io.BytesIO(), buffer_size=buf_size)
                pickler = self.pickler_class(f, protocol=proto)
                pickler.dump(data)
                f.seek(0)
                unpickler = self.unpickler_class(f)
                self.assertEqual(unpickler.load(), data)


# Tests for dispatch_table attribute 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:17,代码来源:pickletester.py

示例6: load

# 需要导入模块: import io [as 别名]
# 或者: from io import BufferedRandom [as 别名]
def load(self, source, mode='t', encoding=None):

        # Prepare source
        source = helpers.requote_uri(source)

        # Prepare bytes
        try:
            parts = urlparse(source, allow_fragments=False)
            response = self.__s3_client.get_object(Bucket=parts.netloc, Key=parts.path[1:])
            # https://github.com/frictionlessdata/tabulator-py/issues/271
            bytes = io.BufferedRandom(io.BytesIO())
            bytes.write(response['Body'].read())
            bytes.seek(0)
            if self.__stats:
                bytes = helpers.BytesStatsWrapper(bytes, self.__stats)
        except Exception as exception:
            raise exceptions.LoadingError(str(exception))

        # Return bytes
        if mode == 'b':
            return bytes

        # Detect encoding
        if self.__bytes_sample_size:
            sample = bytes.read(self.__bytes_sample_size)
            bytes.seek(0)
            encoding = helpers.detect_encoding(sample, encoding)

        # Prepare chars
        chars = io.TextIOWrapper(bytes, encoding)

        return chars 
开发者ID:frictionlessdata,项目名称:tabulator-py,代码行数:34,代码来源:aws.py

示例7: load

# 需要导入模块: import io [as 别名]
# 或者: from io import BufferedRandom [as 别名]
def load(self, source, mode='t', encoding=None):

        # Prepare source
        source = helpers.requote_uri(source)

        # Prepare bytes
        try:
            bytes = _RemoteStream(source, self.__http_session, self.__http_timeout).open()
            if not self.__http_stream:
                buffer = io.BufferedRandom(io.BytesIO())
                buffer.write(bytes.read())
                buffer.seek(0)
                bytes = buffer
            if self.__stats:
                bytes = helpers.BytesStatsWrapper(bytes, self.__stats)
        except IOError as exception:
            raise exceptions.HTTPError(str(exception))

        # Return bytes
        if mode == 'b':
            return bytes

        # Detect encoding
        if self.__bytes_sample_size:
            sample = bytes.read(self.__bytes_sample_size)[:self.__bytes_sample_size]
            bytes.seek(0)
            encoding = helpers.detect_encoding(sample, encoding)

        # Prepare chars
        chars = io.TextIOWrapper(bytes, encoding)

        return chars


# Internal 
开发者ID:frictionlessdata,项目名称:tabulator-py,代码行数:37,代码来源:remote.py

示例8: test_make_stream_reader_writer

# 需要导入模块: import io [as 别名]
# 或者: from io import BufferedRandom [as 别名]
def test_make_stream_reader_writer(self):
        f = io.BytesIO(b"Hello")
        s = iotools.make_stream("foo", f, "+b", buffering=1)
        self.assertIsInstance(s, io.BufferedRandom)
        self.assertEqual(s.read(), b"Hello")
        s.write(b" World")
        self.assertEqual(f.getvalue(), b"Hello World") 
开发者ID:PyFilesystem,项目名称:pyfilesystem2,代码行数:9,代码来源:test_iotools.py

示例9: make_stream

# 需要导入模块: import io [as 别名]
# 或者: from io import BufferedRandom [as 别名]
def make_stream(
    name,  # type: Text
    bin_file,  # type: RawIOBase
    mode="r",  # type: Text
    buffering=-1,  # type: int
    encoding=None,  # type: Optional[Text]
    errors=None,  # type: Optional[Text]
    newline="",  # type: Optional[Text]
    line_buffering=False,  # type: bool
    **kwargs  # type: Any
):
    # type: (...) -> IO
    """Take a Python 2.x binary file and return an IO Stream.
    """
    reading = "r" in mode
    writing = "w" in mode
    appending = "a" in mode
    binary = "b" in mode
    if "+" in mode:
        reading = True
        writing = True

    encoding = None if binary else (encoding or "utf-8")

    io_object = RawWrapper(bin_file, mode=mode, name=name)  # type: io.IOBase
    if buffering >= 0:
        if reading and writing:
            io_object = io.BufferedRandom(
                typing.cast(io.RawIOBase, io_object),
                buffering or io.DEFAULT_BUFFER_SIZE,
            )
        elif reading:
            io_object = io.BufferedReader(
                typing.cast(io.RawIOBase, io_object),
                buffering or io.DEFAULT_BUFFER_SIZE,
            )
        elif writing or appending:
            io_object = io.BufferedWriter(
                typing.cast(io.RawIOBase, io_object),
                buffering or io.DEFAULT_BUFFER_SIZE,
            )

    if not binary:
        io_object = io.TextIOWrapper(
            io_object,
            encoding=encoding,
            errors=errors,
            newline=newline,
            line_buffering=line_buffering,
        )

    return io_object 
开发者ID:PyFilesystem,项目名称:pyfilesystem2,代码行数:54,代码来源:iotools.py


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