python类SEEK_END的实例源码

tarfile.py 文件源码 项目:aws-cfn-plex 作者: lordmuffin 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def seek(self, pos, whence=os.SEEK_SET):
        """Seek to a position in the file.
        """
        if self.closed:
            raise ValueError("I/O operation on closed file")

        if whence == os.SEEK_SET:
            self.position = min(max(pos, 0), self.size)
        elif whence == os.SEEK_CUR:
            if pos < 0:
                self.position = max(self.position + pos, 0)
            else:
                self.position = min(self.position + pos, self.size)
        elif whence == os.SEEK_END:
            self.position = max(min(self.size + pos, self.size), 0)
        else:
            raise ValueError("Invalid argument")

        self.buffer = b""
        self.fileobj.seek(self.position)
tarfile.py 文件源码 项目:django 作者: alexsukhrin 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def seek(self, pos, whence=os.SEEK_SET):
        """Seek to a position in the file.
        """
        if self.closed:
            raise ValueError("I/O operation on closed file")

        if whence == os.SEEK_SET:
            self.position = min(max(pos, 0), self.size)
        elif whence == os.SEEK_CUR:
            if pos < 0:
                self.position = max(self.position + pos, 0)
            else:
                self.position = min(self.position + pos, self.size)
        elif whence == os.SEEK_END:
            self.position = max(min(self.size + pos, self.size), 0)
        else:
            raise ValueError("Invalid argument")

        self.buffer = b""
        self.fileobj.seek(self.position)
tarfile.py 文件源码 项目:RPoint 作者: george17-meet 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def seek(self, pos, whence=os.SEEK_SET):
        """Seek to a position in the file.
        """
        if self.closed:
            raise ValueError("I/O operation on closed file")

        if whence == os.SEEK_SET:
            self.position = min(max(pos, 0), self.size)
        elif whence == os.SEEK_CUR:
            if pos < 0:
                self.position = max(self.position + pos, 0)
            else:
                self.position = min(self.position + pos, self.size)
        elif whence == os.SEEK_END:
            self.position = max(min(self.size + pos, self.size), 0)
        else:
            raise ValueError("Invalid argument")

        self.buffer = b""
        self.fileobj.seek(self.position)
tarfile.py 文件源码 项目:isni-reconcile 作者: cmh2166 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def seek(self, pos, whence=os.SEEK_SET):
        """Seek to a position in the file.
        """
        if self.closed:
            raise ValueError("I/O operation on closed file")

        if whence == os.SEEK_SET:
            self.position = min(max(pos, 0), self.size)
        elif whence == os.SEEK_CUR:
            if pos < 0:
                self.position = max(self.position + pos, 0)
            else:
                self.position = min(self.position + pos, self.size)
        elif whence == os.SEEK_END:
            self.position = max(min(self.size + pos, self.size), 0)
        else:
            raise ValueError("Invalid argument")

        self.buffer = b""
        self.fileobj.seek(self.position)
tarfile.py 文件源码 项目:AshsSDK 作者: thehappydinoa 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def seek(self, pos, whence=os.SEEK_SET):
        """Seek to a position in the file.
        """
        if self.closed:
            raise ValueError("I/O operation on closed file")

        if whence == os.SEEK_SET:
            self.position = min(max(pos, 0), self.size)
        elif whence == os.SEEK_CUR:
            if pos < 0:
                self.position = max(self.position + pos, 0)
            else:
                self.position = min(self.position + pos, self.size)
        elif whence == os.SEEK_END:
            self.position = max(min(self.size + pos, self.size), 0)
        else:
            raise ValueError("Invalid argument")

        self.buffer = b""
        self.fileobj.seek(self.position)
container.py 文件源码 项目:python-ebml 作者: QBobWatson 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __init__(self, f, summary=True):
        """Args:
         + f: Either a file name or a seekable binary stream.
         + summary: If True, call self.read_summary().
        """
        super().__init__(0)
        if isinstance(f, IOBase):
            self.stream = f
        else:
            self.stream = open(f, 'rb')
        self.stream.seek(0, SEEK_END)
        self.stream_size = self.stream.tell()
        self.stream.seek(0, SEEK_SET)

        if summary:
            self.read_summary()
tarfile.py 文件源码 项目:habilitacion 作者: GabrielBD 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def seek(self, pos, whence=os.SEEK_SET):
        """Seek to a position in the file.
        """
        if self.closed:
            raise ValueError("I/O operation on closed file")

        if whence == os.SEEK_SET:
            self.position = min(max(pos, 0), self.size)
        elif whence == os.SEEK_CUR:
            if pos < 0:
                self.position = max(self.position + pos, 0)
            else:
                self.position = min(self.position + pos, self.size)
        elif whence == os.SEEK_END:
            self.position = max(min(self.size + pos, self.size), 0)
        else:
            raise ValueError("Invalid argument")

        self.buffer = b""
        self.fileobj.seek(self.position)
file.py 文件源码 项目:Intranet-Penetration 作者: yuxiaokui 项目源码 文件源码 阅读 47 收藏 0 点赞 0 评论 0
def seek(self, offset, whence=os.SEEK_SET):
    """Set the file's current position.

    Args:
      offset: seek offset as number.
      whence: seek mode. Supported modes are os.SEEK_SET (absolute seek),
        and os.SEEK_CUR (seek relative to the current position) and os.SEEK_END
        (seek relative to the end, offset should be negative).
    """
    self._verify_read_mode()
    if whence == os.SEEK_SET:
      self._offset = offset
    elif whence == os.SEEK_CUR:
      self._offset += offset
    elif whence == os.SEEK_END:
      file_stat = self.stat()
      self._offset = file_stat.st_size + offset
    else:
      raise InvalidArgumentError('Whence mode %d is not supported', whence)
file.py 文件源码 项目:Intranet-Penetration 作者: yuxiaokui 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def seek(self, offset, whence=os.SEEK_SET):
    """Set the file's current position.

    Args:
      offset: seek offset as number.
      whence: seek mode. Supported modes are os.SEEK_SET (absolute seek),
        os.SEEK_CUR (seek relative to the current position), and os.SEEK_END
        (seek relative to the end, offset should be negative).
    """
    if whence == os.SEEK_SET:
      self._position = offset
    elif whence == os.SEEK_CUR:
      self._position += offset
    elif whence == os.SEEK_END:
      file_stat = stat(self._filename)
      self._position = file_stat.st_size + offset
    else:
      raise InvalidArgumentError('Whence mode %d is not supported', whence)
    self._buffer = ''
    self._buffer_pos = 0
    self._eof = False
tarfile.py 文件源码 项目:flasky 作者: RoseOu 项目源码 文件源码 阅读 74 收藏 0 点赞 0 评论 0
def seek(self, pos, whence=os.SEEK_SET):
        """Seek to a position in the file.
        """
        if self.closed:
            raise ValueError("I/O operation on closed file")

        if whence == os.SEEK_SET:
            self.position = min(max(pos, 0), self.size)
        elif whence == os.SEEK_CUR:
            if pos < 0:
                self.position = max(self.position + pos, 0)
            else:
                self.position = min(self.position + pos, self.size)
        elif whence == os.SEEK_END:
            self.position = max(min(self.size + pos, self.size), 0)
        else:
            raise ValueError("Invalid argument")

        self.buffer = b""
        self.fileobj.seek(self.position)
test_hobeta.py 文件源码 项目:zxtools 作者: codeatcpp 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_strip_header1(self):
        test_input_file = io.BytesIO(b"\x46\x2E\x6C\x6F\x61\x64\x2E\x41"
                                     b"\x43\x00\x80\xF9\x06\x00\x07\xB5"
                                     b"\x50\x00\x00\x3B\x20\x4C\x4F\x41"
                                     b"\x44\x45\x52\x20\x66\x6F\x72")
        temp_output_path, bytes_count = self.strip_header(
            test_input_file, True)

        temp_output_file = open(temp_output_path, "rb")
        temp_output_file.seek(0, os.SEEK_END)
        try:
            self.assertEqual(temp_output_file.tell(), 14)
            self.assertEqual(bytes_count, 14)
        finally:
            temp_output_file.close()
            os.remove(temp_output_path)
test_hobeta.py 文件源码 项目:zxtools 作者: codeatcpp 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_strip_header2(self):
        test_input_file = io.BytesIO(b"\x46\x2E\x6C\x6F\x61\x64\x2E\x41"
                                     b"\x43\x00\x80\xF9\x06\x00\x07\xB5"
                                     b"\x50\x00\x00\x3B\x20\x4C\x4F\x41"
                                     b"\x44\x45\x52\x20\x66\x6F\x72\x20\x20")
        temp_output_path, bytes_count = self.strip_header(
            test_input_file, False)

        temp_output_file = open(temp_output_path, "rb")
        temp_output_file.seek(0, os.SEEK_END)
        try:
            self.assertEqual(temp_output_file.tell(), 16)
            self.assertEqual(bytes_count, 16)
        finally:
            temp_output_file.close()
            os.remove(temp_output_path)
test_hobeta.py 文件源码 项目:zxtools 作者: codeatcpp 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_strip_header3(self):
        test_input_file = io.BytesIO(b"\x46\x2E\x6C\x6F\x61\x64\x2E\x41"
                                     b"\x43\x00\x80\x0A\x00\x00\x07\xB5"
                                     b"\x50\x00\x00\x3B\x20\x4C\x4F\x41"
                                     b"\x44\x45\x52\x20\x66\x6F\x72\x20")
        temp_output_path, bytes_count = self.strip_header(
            test_input_file, False)

        temp_output_file = open(temp_output_path, "rb")
        temp_output_file.seek(0, os.SEEK_END)
        try:
            self.assertEqual(temp_output_file.tell(), 10)
            self.assertEqual(bytes_count, 10)
        finally:
            temp_output_file.close()
            os.remove(temp_output_path)
logging.py 文件源码 项目:p2pool-unitus 作者: amarian12 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def reopen(self):
        if self.inner_file is not None:
            self.inner_file.close()
        open(self.filename, 'a').close()
        f = open(self.filename, 'rb')
        f.seek(0, os.SEEK_END)
        length = f.tell()
        if length > 100*1000*1000:
            f.seek(-1000*1000, os.SEEK_END)
            while True:
                if f.read(1) in ('', '\n'):
                    break
            data = f.read()
            f.close()
            f = open(self.filename, 'wb')
            f.write(data)
        f.close()
        self.inner_file = codecs.open(self.filename, 'a', 'utf-8')
file.py 文件源码 项目:MKFQ 作者: maojingios 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def seek(self, offset, whence=os.SEEK_SET):
    """Set the file's current position.

    Args:
      offset: seek offset as number.
      whence: seek mode. Supported modes are os.SEEK_SET (absolute seek),
        and os.SEEK_CUR (seek relative to the current position) and os.SEEK_END
        (seek relative to the end, offset should be negative).
    """
    self._verify_read_mode()
    if whence == os.SEEK_SET:
      self._offset = offset
    elif whence == os.SEEK_CUR:
      self._offset += offset
    elif whence == os.SEEK_END:
      file_stat = self.stat()
      self._offset = file_stat.st_size + offset
    else:
      raise InvalidArgumentError('Whence mode %d is not supported', whence)
file.py 文件源码 项目:MKFQ 作者: maojingios 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def seek(self, offset, whence=os.SEEK_SET):
    """Set the file's current position.

    Args:
      offset: seek offset as number.
      whence: seek mode. Supported modes are os.SEEK_SET (absolute seek),
        os.SEEK_CUR (seek relative to the current position), and os.SEEK_END
        (seek relative to the end, offset should be negative).
    """
    if whence == os.SEEK_SET:
      self._position = offset
    elif whence == os.SEEK_CUR:
      self._position += offset
    elif whence == os.SEEK_END:
      file_stat = stat(self._filename)
      self._position = file_stat.st_size + offset
    else:
      raise InvalidArgumentError('Whence mode %d is not supported', whence)
    self._buffer = ''
    self._buffer_pos = 0
    self._eof = False
github_stats.py 文件源码 项目:scraper 作者: LLNL 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def write_org_json(self, date=(datetime.date.today()),
        organization='llnl',dict_to_write={}, path_ending_type='',
        is_list=False):
        """
        Writes stats from the organization to JSON.
        """
        path = ('../github-data/' + organization + '-org/'
            + path_ending_type + '/' + str(date) + '.json')
        self.checkDir(path)
        with open(path, 'w') as out_clear:#clear old data
            out_clear.close()
        with open(path, 'a') as out:
            if is_list:#used for list of items
                out.write('[')
            for item in dict_to_write:
                out.write(json.dumps(dict_to_write[item], sort_keys=True,
                    indent=4, separators=(',', ': ')) + ',')
            out.seek(-1, os.SEEK_END)#kill last comma
            out.truncate()
            if is_list:
                out.write(']')
        out.close()
tarfile.py 文件源码 项目:flickr_downloader 作者: Denisolt 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def seek(self, pos, whence=os.SEEK_SET):
        """Seek to a position in the file.
        """
        if self.closed:
            raise ValueError("I/O operation on closed file")

        if whence == os.SEEK_SET:
            self.position = min(max(pos, 0), self.size)
        elif whence == os.SEEK_CUR:
            if pos < 0:
                self.position = max(self.position + pos, 0)
            else:
                self.position = min(self.position + pos, self.size)
        elif whence == os.SEEK_END:
            self.position = max(min(self.size + pos, self.size), 0)
        else:
            raise ValueError("Invalid argument")

        self.buffer = b""
        self.fileobj.seek(self.position)
tarfile.py 文件源码 项目:threatdetectionservice 作者: flyballlabs 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def seek(self, pos, whence=os.SEEK_SET):
        """Seek to a position in the file.
        """
        if self.closed:
            raise ValueError("I/O operation on closed file")

        if whence == os.SEEK_SET:
            self.position = min(max(pos, 0), self.size)
        elif whence == os.SEEK_CUR:
            if pos < 0:
                self.position = max(self.position + pos, 0)
            else:
                self.position = min(self.position + pos, self.size)
        elif whence == os.SEEK_END:
            self.position = max(min(self.size + pos, self.size), 0)
        else:
            raise ValueError("Invalid argument")

        self.buffer = b""
        self.fileobj.seek(self.position)
tarfile.py 文件源码 项目:oa_qian 作者: sunqb 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def seek(self, pos, whence=os.SEEK_SET):
        """Seek to a position in the file.
        """
        if self.closed:
            raise ValueError("I/O operation on closed file")

        if whence == os.SEEK_SET:
            self.position = min(max(pos, 0), self.size)
        elif whence == os.SEEK_CUR:
            if pos < 0:
                self.position = max(self.position + pos, 0)
            else:
                self.position = min(self.position + pos, self.size)
        elif whence == os.SEEK_END:
            self.position = max(min(self.size + pos, self.size), 0)
        else:
            raise ValueError("Invalid argument")

        self.buffer = b""
        self.fileobj.seek(self.position)


问题


面经


文章

微信
公众号

扫码关注公众号