Python os.SEEK_CUR Examples
The following are 30
code examples of os.SEEK_CUR().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os
, or try the search function
.
Example #1
Source File: tarfile.py From oss-ftp with MIT License | 6 votes |
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)
Example #2
Source File: socks.py From vulscan with MIT License | 6 votes |
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))
Example #3
Source File: petition.py From petitions with MIT License | 6 votes |
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
Example #4
Source File: tarfile.py From jbox with MIT License | 6 votes |
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)
Example #5
Source File: atrace_from_file_agent.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 6 votes |
def is_perfetto(from_file): # Starts with a preamble for field ID=1 (TracePacket) if ord(from_file.read(1)) != 0x0a: return False for _ in range(10): # Check the first 10 packets are structured correctly # Then a var int that specifies field size field_size = 0 shift = 0 while True: c = ord(from_file.read(1)) field_size |= (c & 0x7f) << shift shift += 7 if not c & 0x80: break # The packet itself from_file.seek(field_size, os.SEEK_CUR) # The preamble for the next field ID=1 (TracePacket) if ord(from_file.read(1)) != 0x0a: return False # Go back to the beginning of the file from_file.seek(0) return True
Example #6
Source File: __init__.py From Sony-PMCA-RE with MIT License | 6 votes |
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')
Example #7
Source File: tarfile.py From meddle with MIT License | 6 votes |
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)
Example #8
Source File: tarfile.py From hacktoberfest2018 with GNU General Public License v3.0 | 6 votes |
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)
Example #9
Source File: tarfile.py From FuYiSpider with Apache License 2.0 | 6 votes |
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)
Example #10
Source File: atrace_from_file_agent.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 6 votes |
def is_perfetto(from_file): # Starts with a preamble for field ID=1 (TracePacket) if ord(from_file.read(1)) != 0x0a: return False for _ in range(10): # Check the first 10 packets are structured correctly # Then a var int that specifies field size field_size = 0 shift = 0 while True: c = ord(from_file.read(1)) field_size |= (c & 0x7f) << shift shift += 7 if not c & 0x80: break # The packet itself from_file.seek(field_size, os.SEEK_CUR) # The preamble for the next field ID=1 (TracePacket) if ord(from_file.read(1)) != 0x0a: return False # Go back to the beginning of the file from_file.seek(0) return True
Example #11
Source File: tarfile.py From BinderFilter with MIT License | 6 votes |
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)
Example #12
Source File: tarfile.py From deepWordBug with Apache License 2.0 | 6 votes |
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)
Example #13
Source File: tarfile.py From Computable with MIT License | 6 votes |
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)
Example #14
Source File: r_language.py From rfmt with Apache License 2.0 | 6 votes |
def UnGetChar(self): """Push the last fetched character back onto the input stream.""" # Currently, no provision is made for calling UnGetChar twice, with no # intervening GetChar. if self.last_getc is None: raise AssertionError('Too many UnGetChar\'s') # Don't back up if we're past the end of the file, but do back up if we just # arrived there. if self.last_getc != 'R_EOF': self.stream.seek(-1, os.SEEK_CUR) if self.last_getc == '\n': self.col, self.last_col = self.last_col, 0 self.line -= 1 self.last_getc = None else: self.col -= 1
Example #15
Source File: tarfile.py From oss-ftp with MIT License | 6 votes |
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)
Example #16
Source File: tarfile.py From FuYiSpider with Apache License 2.0 | 6 votes |
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)
Example #17
Source File: tarfile.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
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)
Example #18
Source File: tarfile.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
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)
Example #19
Source File: socks.py From Google-Alfred3-Workflow with MIT License | 6 votes |
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))
Example #20
Source File: tarfile.py From anpr with Creative Commons Attribution 4.0 International | 6 votes |
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)
Example #21
Source File: tarfile.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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)
Example #22
Source File: pygtide.py From pygtide with Mozilla Public License 2.0 | 6 votes |
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")
Example #23
Source File: pygtide.py From pygtide with Mozilla Public License 2.0 | 6 votes |
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]))
Example #24
Source File: chrome_cache.py From plaso with Apache License 2.0 | 6 votes |
def ParseFileObject(self, parser_mediator, file_object): """Parses a file-like object. Args: parser_mediator (ParserMediator): a parser mediator. file_object (dfvfs.FileIO): a file-like object to parse. Raises: ParseError: when the file cannot be parsed. """ try: self._ParseFileHeader(file_object) except errors.ParseError as exception: raise errors.ParseError( 'Unable to parse index file header with error: {0!s}'.format( exception)) # Skip over the LRU data, which is 112 bytes in size. file_object.seek(112, os.SEEK_CUR) self._ParseIndexTable(file_object)
Example #25
Source File: tarfile.py From pipenv with MIT License | 6 votes |
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)
Example #26
Source File: tarfile.py From pex with Apache License 2.0 | 6 votes |
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)
Example #27
Source File: tarfile.py From GraphicDesignPatternByPython with MIT License | 6 votes |
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)
Example #28
Source File: socks.py From HTTPAceProxy with GNU General Public License v3.0 | 6 votes |
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))
Example #29
Source File: tarfile.py From pipenv with MIT License | 6 votes |
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)
Example #30
Source File: CPH_Merger.py From burp-cph with MIT License | 6 votes |
def write_imports(opened_file): line = opened_file.readline() while line: if line.startswith('class'): opened_file.seek(len(line) * -1, SEEK_CUR) merged_file.write('\n') break if line.strip().startswith('from CPH_Config')\ or line.strip().startswith('from CPH_Help' )\ or line.strip().startswith('from tinyweb' )\ or line.strip().startswith('#' )\ or not line.strip(): line = opened_file.readline() continue merged_file.write(line) line = opened_file.readline()