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