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


Python os.SEEK_CUR属性代码示例

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


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

示例1: recvfrom

# 需要导入模块: import os [as 别名]
# 或者: from os import SEEK_CUR [as 别名]
def recvfrom(self, bufsize, flags=0):
        if self.type != socket.SOCK_DGRAM:
            return _BaseSocket.recvfrom(self, bufsize, flags)
        if not self._proxyconn:
            self.bind(("", 0))

        buf = BytesIO(_BaseSocket.recv(self, bufsize, flags))
        buf.seek(+2, SEEK_CUR)
        frag = buf.read(1)
        if ord(frag):
            raise NotImplementedError("Received UDP packet fragment")
        fromhost, fromport = self._read_SOCKS5_address(buf)

        if self.proxy_peername:
            peerhost, peerport = self.proxy_peername
            if fromhost != peerhost or peerport not in (0, fromport):
                raise socket.error(EAGAIN, "Packet filtered")

        return (buf.read(), (fromhost, fromport)) 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:21,代码来源:socks.py

示例2: seek

# 需要导入模块: import os [as 别名]
# 或者: from os import SEEK_CUR [as 别名]
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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:tarfile.py

示例3: get_latest_saved_article_id

# 需要导入模块: import os [as 别名]
# 或者: from os import SEEK_CUR [as 别名]
def get_latest_saved_article_id() -> int:
    """이미 저장한 가장 최근 글번호를 가져오기. 저장된 글이 없으면 0을 반환"""
    # 글이 없으면 0
    if not os.path.isfile(CSV_WHOLE):
        return 0

    # 파일 끝 부분에서 몇 줄 읽어온 뒤 마지막 줄의 첫 칼럼(article_id) 반환
    with open(CSV_WHOLE, 'rb') as f:
        # 마지막 줄을 빠르게 찾기 위해 "거의" 끝 부분으로 이동
        f.seek(0, os.SEEK_END)
        f.seek(-min([f.tell(), 1024 * 100]), os.SEEK_CUR)

        # 마지막 줄에서 article id 추출
        last_line = f.readlines()[-1].decode('utf-8')
        article_id = int(last_line.split(',')[0])

        return article_id 
开发者ID:akngs,项目名称:petitions,代码行数:19,代码来源:petition.py

示例4: readDat

# 需要导入模块: import os [as 别名]
# 或者: from os import SEEK_CUR [as 别名]
def readDat(file):
 """"Extract the firmware from a .dat file. Returns the offset and the size of the firmware data."""
 file.seek(0)
 header = DatHeader.unpack(file.read(DatHeader.size))
 if header.magic != datHeaderMagic:
  raise Exception('Wrong magic')

 while True:
  data = file.read(DatChunkHeader.size)
  if len(data) != DatChunkHeader.size:
   break
  chunk = DatChunkHeader.unpack(data)
  if chunk.type == b'FDAT':
   return file.tell(), chunk.size
  file.seek(chunk.size, os.SEEK_CUR)
 raise Exception('FDAT chunk not found') 
开发者ID:ma1co,项目名称:Sony-PMCA-RE,代码行数:18,代码来源:__init__.py

示例5: seek

# 需要导入模块: import os [as 别名]
# 或者: from os import SEEK_CUR [as 别名]
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 = ""
        self.fileobj.seek(self.position) 
开发者ID:glmcdona,项目名称:meddle,代码行数:22,代码来源:tarfile.py

示例6: recvfrom

# 需要导入模块: import os [as 别名]
# 或者: from os import SEEK_CUR [as 别名]
def recvfrom(self, bufsize, flags=0):
        if self.type != socket.SOCK_DGRAM:
            return super(socksocket, self).recvfrom(bufsize, flags)
        if not self._proxyconn:
            self.bind(("", 0))

        buf = BytesIO(super(socksocket, self).recv(bufsize + 1024, flags))
        buf.seek(2, SEEK_CUR)
        frag = buf.read(1)
        if ord(frag):
            raise NotImplementedError("Received UDP packet fragment")
        fromhost, fromport = self._read_SOCKS5_address(buf)

        if self.proxy_peername:
            peerhost, peerport = self.proxy_peername
            if fromhost != peerhost or peerport not in (0, fromport):
                raise socket.error(EAGAIN, "Packet filtered")

        return (buf.read(bufsize), (fromhost, fromport)) 
开发者ID:wkeeling,项目名称:selenium-wire,代码行数:21,代码来源:socks.py

示例7: get_last_line_from_file

# 需要导入模块: import os [as 别名]
# 或者: from os import SEEK_CUR [as 别名]
def get_last_line_from_file(file):
    # concerns to address(may be much later):
        # how will last line lookup work with log rotation when a new file is created?
            #- will that new file be empty at any time? or will it have a partial line from the previous file?
    line = None
    if os.stat(file).st_size < 5000:
        # quick hack to handle files with one line
        with open(file, 'r') as f:
            for line in f:
                pass
    else:
        # optimized for large log files
        with open(file, 'rb') as f:
            f.seek(-2, os.SEEK_END)
            while f.read(1) != b'\n':
                f.seek(-2, os.SEEK_CUR)
            line = f.readline().decode()
    return line 
开发者ID:frappe,项目名称:biometric-attendance-sync-tool,代码行数:20,代码来源:erpnext_sync.py

示例8: read_etpolut1_dat

# 需要导入模块: import os [as 别名]
# 或者: from os import SEEK_CUR [as 别名]
def read_etpolut1_dat(self):
        fname = os.path.join(ETPRED_DIR, self.data_dir, 'etpolut1.dat')
        with open(fname, "rb") as f:
            first = f.readline()
            #print(first[0:10])
            while first[0:10] != b"C*********":
                first = f.readline()
                #print(first[0:10])
            first = f.readline()
            # Jump to the second last byte.
            f.seek(-12, os.SEEK_END)
            # Until EOL is found...
            while f.read(1) != b"\n":
                # ...jump back the read byte plus one more.
                f.seek(-2, os.SEEK_CUR)
            last = f.readline()
        # store dates
        self.etpolut1_start = dt.datetime.strptime(first[0:8].decode("utf-8"), "%Y%m%d")
        self.etpolut1_end = dt.datetime.strptime(last[0:8].decode("utf-8"), "%Y%m%d") 
开发者ID:hydrogeoscience,项目名称:pygtide,代码行数:21,代码来源:pygtide.py

示例9: read_etddt_dat

# 需要导入模块: import os [as 别名]
# 或者: from os import SEEK_CUR [as 别名]
def read_etddt_dat(self):
        fname = os.path.join(ETPRED_DIR, self.data_dir, 'etddt.dat')
        with open(fname, "rb") as f:
            first = f.readline()
            while first[0:10] != b"C*********":
                first = f.readline()
            first = f.readline()
            # Jump to the second last byte.
            f.seek(-12, os.SEEK_END)
            # Until EOL is found...
            while f.read(1) != b"\n":
                # ...jump back the read byte plus one more.
                f.seek(-2, os.SEEK_CUR)
            last = f.readline()
        # store dates
        self.etddt_start = self.from_floatyear(float(first[0:10]))
        self.etddt_end = self.from_floatyear(float(last[0:10])) 
开发者ID:hydrogeoscience,项目名称:pygtide,代码行数:19,代码来源:pygtide.py


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