Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3....
File: mailbox.py
elif hasattr(message, "read"):
[1500] Fix | Delete
self._become_message(email.message_from_binary_file(message))
[1501] Fix | Delete
elif message is None:
[1502] Fix | Delete
email.message.Message.__init__(self)
[1503] Fix | Delete
else:
[1504] Fix | Delete
raise TypeError('Invalid message type: %s' % type(message))
[1505] Fix | Delete
[1506] Fix | Delete
def _become_message(self, message):
[1507] Fix | Delete
"""Assume the non-format-specific state of message."""
[1508] Fix | Delete
type_specific = getattr(message, '_type_specific_attributes', [])
[1509] Fix | Delete
for name in message.__dict__:
[1510] Fix | Delete
if name not in type_specific:
[1511] Fix | Delete
self.__dict__[name] = message.__dict__[name]
[1512] Fix | Delete
[1513] Fix | Delete
def _explain_to(self, message):
[1514] Fix | Delete
"""Copy format-specific state to message insofar as possible."""
[1515] Fix | Delete
if isinstance(message, Message):
[1516] Fix | Delete
return # There's nothing format-specific to explain.
[1517] Fix | Delete
else:
[1518] Fix | Delete
raise TypeError('Cannot convert to specified type')
[1519] Fix | Delete
[1520] Fix | Delete
[1521] Fix | Delete
class MaildirMessage(Message):
[1522] Fix | Delete
"""Message with Maildir-specific properties."""
[1523] Fix | Delete
[1524] Fix | Delete
_type_specific_attributes = ['_subdir', '_info', '_date']
[1525] Fix | Delete
[1526] Fix | Delete
def __init__(self, message=None):
[1527] Fix | Delete
"""Initialize a MaildirMessage instance."""
[1528] Fix | Delete
self._subdir = 'new'
[1529] Fix | Delete
self._info = ''
[1530] Fix | Delete
self._date = time.time()
[1531] Fix | Delete
Message.__init__(self, message)
[1532] Fix | Delete
[1533] Fix | Delete
def get_subdir(self):
[1534] Fix | Delete
"""Return 'new' or 'cur'."""
[1535] Fix | Delete
return self._subdir
[1536] Fix | Delete
[1537] Fix | Delete
def set_subdir(self, subdir):
[1538] Fix | Delete
"""Set subdir to 'new' or 'cur'."""
[1539] Fix | Delete
if subdir == 'new' or subdir == 'cur':
[1540] Fix | Delete
self._subdir = subdir
[1541] Fix | Delete
else:
[1542] Fix | Delete
raise ValueError("subdir must be 'new' or 'cur': %s" % subdir)
[1543] Fix | Delete
[1544] Fix | Delete
def get_flags(self):
[1545] Fix | Delete
"""Return as a string the flags that are set."""
[1546] Fix | Delete
if self._info.startswith('2,'):
[1547] Fix | Delete
return self._info[2:]
[1548] Fix | Delete
else:
[1549] Fix | Delete
return ''
[1550] Fix | Delete
[1551] Fix | Delete
def set_flags(self, flags):
[1552] Fix | Delete
"""Set the given flags and unset all others."""
[1553] Fix | Delete
self._info = '2,' + ''.join(sorted(flags))
[1554] Fix | Delete
[1555] Fix | Delete
def add_flag(self, flag):
[1556] Fix | Delete
"""Set the given flag(s) without changing others."""
[1557] Fix | Delete
self.set_flags(''.join(set(self.get_flags()) | set(flag)))
[1558] Fix | Delete
[1559] Fix | Delete
def remove_flag(self, flag):
[1560] Fix | Delete
"""Unset the given string flag(s) without changing others."""
[1561] Fix | Delete
if self.get_flags():
[1562] Fix | Delete
self.set_flags(''.join(set(self.get_flags()) - set(flag)))
[1563] Fix | Delete
[1564] Fix | Delete
def get_date(self):
[1565] Fix | Delete
"""Return delivery date of message, in seconds since the epoch."""
[1566] Fix | Delete
return self._date
[1567] Fix | Delete
[1568] Fix | Delete
def set_date(self, date):
[1569] Fix | Delete
"""Set delivery date of message, in seconds since the epoch."""
[1570] Fix | Delete
try:
[1571] Fix | Delete
self._date = float(date)
[1572] Fix | Delete
except ValueError:
[1573] Fix | Delete
raise TypeError("can't convert to float: %s" % date) from None
[1574] Fix | Delete
[1575] Fix | Delete
def get_info(self):
[1576] Fix | Delete
"""Get the message's "info" as a string."""
[1577] Fix | Delete
return self._info
[1578] Fix | Delete
[1579] Fix | Delete
def set_info(self, info):
[1580] Fix | Delete
"""Set the message's "info" string."""
[1581] Fix | Delete
if isinstance(info, str):
[1582] Fix | Delete
self._info = info
[1583] Fix | Delete
else:
[1584] Fix | Delete
raise TypeError('info must be a string: %s' % type(info))
[1585] Fix | Delete
[1586] Fix | Delete
def _explain_to(self, message):
[1587] Fix | Delete
"""Copy Maildir-specific state to message insofar as possible."""
[1588] Fix | Delete
if isinstance(message, MaildirMessage):
[1589] Fix | Delete
message.set_flags(self.get_flags())
[1590] Fix | Delete
message.set_subdir(self.get_subdir())
[1591] Fix | Delete
message.set_date(self.get_date())
[1592] Fix | Delete
elif isinstance(message, _mboxMMDFMessage):
[1593] Fix | Delete
flags = set(self.get_flags())
[1594] Fix | Delete
if 'S' in flags:
[1595] Fix | Delete
message.add_flag('R')
[1596] Fix | Delete
if self.get_subdir() == 'cur':
[1597] Fix | Delete
message.add_flag('O')
[1598] Fix | Delete
if 'T' in flags:
[1599] Fix | Delete
message.add_flag('D')
[1600] Fix | Delete
if 'F' in flags:
[1601] Fix | Delete
message.add_flag('F')
[1602] Fix | Delete
if 'R' in flags:
[1603] Fix | Delete
message.add_flag('A')
[1604] Fix | Delete
message.set_from('MAILER-DAEMON', time.gmtime(self.get_date()))
[1605] Fix | Delete
elif isinstance(message, MHMessage):
[1606] Fix | Delete
flags = set(self.get_flags())
[1607] Fix | Delete
if 'S' not in flags:
[1608] Fix | Delete
message.add_sequence('unseen')
[1609] Fix | Delete
if 'R' in flags:
[1610] Fix | Delete
message.add_sequence('replied')
[1611] Fix | Delete
if 'F' in flags:
[1612] Fix | Delete
message.add_sequence('flagged')
[1613] Fix | Delete
elif isinstance(message, BabylMessage):
[1614] Fix | Delete
flags = set(self.get_flags())
[1615] Fix | Delete
if 'S' not in flags:
[1616] Fix | Delete
message.add_label('unseen')
[1617] Fix | Delete
if 'T' in flags:
[1618] Fix | Delete
message.add_label('deleted')
[1619] Fix | Delete
if 'R' in flags:
[1620] Fix | Delete
message.add_label('answered')
[1621] Fix | Delete
if 'P' in flags:
[1622] Fix | Delete
message.add_label('forwarded')
[1623] Fix | Delete
elif isinstance(message, Message):
[1624] Fix | Delete
pass
[1625] Fix | Delete
else:
[1626] Fix | Delete
raise TypeError('Cannot convert to specified type: %s' %
[1627] Fix | Delete
type(message))
[1628] Fix | Delete
[1629] Fix | Delete
[1630] Fix | Delete
class _mboxMMDFMessage(Message):
[1631] Fix | Delete
"""Message with mbox- or MMDF-specific properties."""
[1632] Fix | Delete
[1633] Fix | Delete
_type_specific_attributes = ['_from']
[1634] Fix | Delete
[1635] Fix | Delete
def __init__(self, message=None):
[1636] Fix | Delete
"""Initialize an mboxMMDFMessage instance."""
[1637] Fix | Delete
self.set_from('MAILER-DAEMON', True)
[1638] Fix | Delete
if isinstance(message, email.message.Message):
[1639] Fix | Delete
unixfrom = message.get_unixfrom()
[1640] Fix | Delete
if unixfrom is not None and unixfrom.startswith('From '):
[1641] Fix | Delete
self.set_from(unixfrom[5:])
[1642] Fix | Delete
Message.__init__(self, message)
[1643] Fix | Delete
[1644] Fix | Delete
def get_from(self):
[1645] Fix | Delete
"""Return contents of "From " line."""
[1646] Fix | Delete
return self._from
[1647] Fix | Delete
[1648] Fix | Delete
def set_from(self, from_, time_=None):
[1649] Fix | Delete
"""Set "From " line, formatting and appending time_ if specified."""
[1650] Fix | Delete
if time_ is not None:
[1651] Fix | Delete
if time_ is True:
[1652] Fix | Delete
time_ = time.gmtime()
[1653] Fix | Delete
from_ += ' ' + time.asctime(time_)
[1654] Fix | Delete
self._from = from_
[1655] Fix | Delete
[1656] Fix | Delete
def get_flags(self):
[1657] Fix | Delete
"""Return as a string the flags that are set."""
[1658] Fix | Delete
return self.get('Status', '') + self.get('X-Status', '')
[1659] Fix | Delete
[1660] Fix | Delete
def set_flags(self, flags):
[1661] Fix | Delete
"""Set the given flags and unset all others."""
[1662] Fix | Delete
flags = set(flags)
[1663] Fix | Delete
status_flags, xstatus_flags = '', ''
[1664] Fix | Delete
for flag in ('R', 'O'):
[1665] Fix | Delete
if flag in flags:
[1666] Fix | Delete
status_flags += flag
[1667] Fix | Delete
flags.remove(flag)
[1668] Fix | Delete
for flag in ('D', 'F', 'A'):
[1669] Fix | Delete
if flag in flags:
[1670] Fix | Delete
xstatus_flags += flag
[1671] Fix | Delete
flags.remove(flag)
[1672] Fix | Delete
xstatus_flags += ''.join(sorted(flags))
[1673] Fix | Delete
try:
[1674] Fix | Delete
self.replace_header('Status', status_flags)
[1675] Fix | Delete
except KeyError:
[1676] Fix | Delete
self.add_header('Status', status_flags)
[1677] Fix | Delete
try:
[1678] Fix | Delete
self.replace_header('X-Status', xstatus_flags)
[1679] Fix | Delete
except KeyError:
[1680] Fix | Delete
self.add_header('X-Status', xstatus_flags)
[1681] Fix | Delete
[1682] Fix | Delete
def add_flag(self, flag):
[1683] Fix | Delete
"""Set the given flag(s) without changing others."""
[1684] Fix | Delete
self.set_flags(''.join(set(self.get_flags()) | set(flag)))
[1685] Fix | Delete
[1686] Fix | Delete
def remove_flag(self, flag):
[1687] Fix | Delete
"""Unset the given string flag(s) without changing others."""
[1688] Fix | Delete
if 'Status' in self or 'X-Status' in self:
[1689] Fix | Delete
self.set_flags(''.join(set(self.get_flags()) - set(flag)))
[1690] Fix | Delete
[1691] Fix | Delete
def _explain_to(self, message):
[1692] Fix | Delete
"""Copy mbox- or MMDF-specific state to message insofar as possible."""
[1693] Fix | Delete
if isinstance(message, MaildirMessage):
[1694] Fix | Delete
flags = set(self.get_flags())
[1695] Fix | Delete
if 'O' in flags:
[1696] Fix | Delete
message.set_subdir('cur')
[1697] Fix | Delete
if 'F' in flags:
[1698] Fix | Delete
message.add_flag('F')
[1699] Fix | Delete
if 'A' in flags:
[1700] Fix | Delete
message.add_flag('R')
[1701] Fix | Delete
if 'R' in flags:
[1702] Fix | Delete
message.add_flag('S')
[1703] Fix | Delete
if 'D' in flags:
[1704] Fix | Delete
message.add_flag('T')
[1705] Fix | Delete
del message['status']
[1706] Fix | Delete
del message['x-status']
[1707] Fix | Delete
maybe_date = ' '.join(self.get_from().split()[-5:])
[1708] Fix | Delete
try:
[1709] Fix | Delete
message.set_date(calendar.timegm(time.strptime(maybe_date,
[1710] Fix | Delete
'%a %b %d %H:%M:%S %Y')))
[1711] Fix | Delete
except (ValueError, OverflowError):
[1712] Fix | Delete
pass
[1713] Fix | Delete
elif isinstance(message, _mboxMMDFMessage):
[1714] Fix | Delete
message.set_flags(self.get_flags())
[1715] Fix | Delete
message.set_from(self.get_from())
[1716] Fix | Delete
elif isinstance(message, MHMessage):
[1717] Fix | Delete
flags = set(self.get_flags())
[1718] Fix | Delete
if 'R' not in flags:
[1719] Fix | Delete
message.add_sequence('unseen')
[1720] Fix | Delete
if 'A' in flags:
[1721] Fix | Delete
message.add_sequence('replied')
[1722] Fix | Delete
if 'F' in flags:
[1723] Fix | Delete
message.add_sequence('flagged')
[1724] Fix | Delete
del message['status']
[1725] Fix | Delete
del message['x-status']
[1726] Fix | Delete
elif isinstance(message, BabylMessage):
[1727] Fix | Delete
flags = set(self.get_flags())
[1728] Fix | Delete
if 'R' not in flags:
[1729] Fix | Delete
message.add_label('unseen')
[1730] Fix | Delete
if 'D' in flags:
[1731] Fix | Delete
message.add_label('deleted')
[1732] Fix | Delete
if 'A' in flags:
[1733] Fix | Delete
message.add_label('answered')
[1734] Fix | Delete
del message['status']
[1735] Fix | Delete
del message['x-status']
[1736] Fix | Delete
elif isinstance(message, Message):
[1737] Fix | Delete
pass
[1738] Fix | Delete
else:
[1739] Fix | Delete
raise TypeError('Cannot convert to specified type: %s' %
[1740] Fix | Delete
type(message))
[1741] Fix | Delete
[1742] Fix | Delete
[1743] Fix | Delete
class mboxMessage(_mboxMMDFMessage):
[1744] Fix | Delete
"""Message with mbox-specific properties."""
[1745] Fix | Delete
[1746] Fix | Delete
[1747] Fix | Delete
class MHMessage(Message):
[1748] Fix | Delete
"""Message with MH-specific properties."""
[1749] Fix | Delete
[1750] Fix | Delete
_type_specific_attributes = ['_sequences']
[1751] Fix | Delete
[1752] Fix | Delete
def __init__(self, message=None):
[1753] Fix | Delete
"""Initialize an MHMessage instance."""
[1754] Fix | Delete
self._sequences = []
[1755] Fix | Delete
Message.__init__(self, message)
[1756] Fix | Delete
[1757] Fix | Delete
def get_sequences(self):
[1758] Fix | Delete
"""Return a list of sequences that include the message."""
[1759] Fix | Delete
return self._sequences[:]
[1760] Fix | Delete
[1761] Fix | Delete
def set_sequences(self, sequences):
[1762] Fix | Delete
"""Set the list of sequences that include the message."""
[1763] Fix | Delete
self._sequences = list(sequences)
[1764] Fix | Delete
[1765] Fix | Delete
def add_sequence(self, sequence):
[1766] Fix | Delete
"""Add sequence to list of sequences including the message."""
[1767] Fix | Delete
if isinstance(sequence, str):
[1768] Fix | Delete
if not sequence in self._sequences:
[1769] Fix | Delete
self._sequences.append(sequence)
[1770] Fix | Delete
else:
[1771] Fix | Delete
raise TypeError('sequence type must be str: %s' % type(sequence))
[1772] Fix | Delete
[1773] Fix | Delete
def remove_sequence(self, sequence):
[1774] Fix | Delete
"""Remove sequence from the list of sequences including the message."""
[1775] Fix | Delete
try:
[1776] Fix | Delete
self._sequences.remove(sequence)
[1777] Fix | Delete
except ValueError:
[1778] Fix | Delete
pass
[1779] Fix | Delete
[1780] Fix | Delete
def _explain_to(self, message):
[1781] Fix | Delete
"""Copy MH-specific state to message insofar as possible."""
[1782] Fix | Delete
if isinstance(message, MaildirMessage):
[1783] Fix | Delete
sequences = set(self.get_sequences())
[1784] Fix | Delete
if 'unseen' in sequences:
[1785] Fix | Delete
message.set_subdir('cur')
[1786] Fix | Delete
else:
[1787] Fix | Delete
message.set_subdir('cur')
[1788] Fix | Delete
message.add_flag('S')
[1789] Fix | Delete
if 'flagged' in sequences:
[1790] Fix | Delete
message.add_flag('F')
[1791] Fix | Delete
if 'replied' in sequences:
[1792] Fix | Delete
message.add_flag('R')
[1793] Fix | Delete
elif isinstance(message, _mboxMMDFMessage):
[1794] Fix | Delete
sequences = set(self.get_sequences())
[1795] Fix | Delete
if 'unseen' not in sequences:
[1796] Fix | Delete
message.add_flag('RO')
[1797] Fix | Delete
else:
[1798] Fix | Delete
message.add_flag('O')
[1799] Fix | Delete
if 'flagged' in sequences:
[1800] Fix | Delete
message.add_flag('F')
[1801] Fix | Delete
if 'replied' in sequences:
[1802] Fix | Delete
message.add_flag('A')
[1803] Fix | Delete
elif isinstance(message, MHMessage):
[1804] Fix | Delete
for sequence in self.get_sequences():
[1805] Fix | Delete
message.add_sequence(sequence)
[1806] Fix | Delete
elif isinstance(message, BabylMessage):
[1807] Fix | Delete
sequences = set(self.get_sequences())
[1808] Fix | Delete
if 'unseen' in sequences:
[1809] Fix | Delete
message.add_label('unseen')
[1810] Fix | Delete
if 'replied' in sequences:
[1811] Fix | Delete
message.add_label('answered')
[1812] Fix | Delete
elif isinstance(message, Message):
[1813] Fix | Delete
pass
[1814] Fix | Delete
else:
[1815] Fix | Delete
raise TypeError('Cannot convert to specified type: %s' %
[1816] Fix | Delete
type(message))
[1817] Fix | Delete
[1818] Fix | Delete
[1819] Fix | Delete
class BabylMessage(Message):
[1820] Fix | Delete
"""Message with Babyl-specific properties."""
[1821] Fix | Delete
[1822] Fix | Delete
_type_specific_attributes = ['_labels', '_visible']
[1823] Fix | Delete
[1824] Fix | Delete
def __init__(self, message=None):
[1825] Fix | Delete
"""Initialize a BabylMessage instance."""
[1826] Fix | Delete
self._labels = []
[1827] Fix | Delete
self._visible = Message()
[1828] Fix | Delete
Message.__init__(self, message)
[1829] Fix | Delete
[1830] Fix | Delete
def get_labels(self):
[1831] Fix | Delete
"""Return a list of labels on the message."""
[1832] Fix | Delete
return self._labels[:]
[1833] Fix | Delete
[1834] Fix | Delete
def set_labels(self, labels):
[1835] Fix | Delete
"""Set the list of labels on the message."""
[1836] Fix | Delete
self._labels = list(labels)
[1837] Fix | Delete
[1838] Fix | Delete
def add_label(self, label):
[1839] Fix | Delete
"""Add label to list of labels on the message."""
[1840] Fix | Delete
if isinstance(label, str):
[1841] Fix | Delete
if label not in self._labels:
[1842] Fix | Delete
self._labels.append(label)
[1843] Fix | Delete
else:
[1844] Fix | Delete
raise TypeError('label must be a string: %s' % type(label))
[1845] Fix | Delete
[1846] Fix | Delete
def remove_label(self, label):
[1847] Fix | Delete
"""Remove label from the list of labels on the message."""
[1848] Fix | Delete
try:
[1849] Fix | Delete
self._labels.remove(label)
[1850] Fix | Delete
except ValueError:
[1851] Fix | Delete
pass
[1852] Fix | Delete
[1853] Fix | Delete
def get_visible(self):
[1854] Fix | Delete
"""Return a Message representation of visible headers."""
[1855] Fix | Delete
return Message(self._visible)
[1856] Fix | Delete
[1857] Fix | Delete
def set_visible(self, visible):
[1858] Fix | Delete
"""Set the Message representation of visible headers."""
[1859] Fix | Delete
self._visible = Message(visible)
[1860] Fix | Delete
[1861] Fix | Delete
def update_visible(self):
[1862] Fix | Delete
"""Update and/or sensibly generate a set of visible headers."""
[1863] Fix | Delete
for header in self._visible.keys():
[1864] Fix | Delete
if header in self:
[1865] Fix | Delete
self._visible.replace_header(header, self[header])
[1866] Fix | Delete
else:
[1867] Fix | Delete
del self._visible[header]
[1868] Fix | Delete
for header in ('Date', 'From', 'Reply-To', 'To', 'CC', 'Subject'):
[1869] Fix | Delete
if header in self and header not in self._visible:
[1870] Fix | Delete
self._visible[header] = self[header]
[1871] Fix | Delete
[1872] Fix | Delete
def _explain_to(self, message):
[1873] Fix | Delete
"""Copy Babyl-specific state to message insofar as possible."""
[1874] Fix | Delete
if isinstance(message, MaildirMessage):
[1875] Fix | Delete
labels = set(self.get_labels())
[1876] Fix | Delete
if 'unseen' in labels:
[1877] Fix | Delete
message.set_subdir('cur')
[1878] Fix | Delete
else:
[1879] Fix | Delete
message.set_subdir('cur')
[1880] Fix | Delete
message.add_flag('S')
[1881] Fix | Delete
if 'forwarded' in labels or 'resent' in labels:
[1882] Fix | Delete
message.add_flag('P')
[1883] Fix | Delete
if 'answered' in labels:
[1884] Fix | Delete
message.add_flag('R')
[1885] Fix | Delete
if 'deleted' in labels:
[1886] Fix | Delete
message.add_flag('T')
[1887] Fix | Delete
elif isinstance(message, _mboxMMDFMessage):
[1888] Fix | Delete
labels = set(self.get_labels())
[1889] Fix | Delete
if 'unseen' not in labels:
[1890] Fix | Delete
message.add_flag('RO')
[1891] Fix | Delete
else:
[1892] Fix | Delete
message.add_flag('O')
[1893] Fix | Delete
if 'deleted' in labels:
[1894] Fix | Delete
message.add_flag('D')
[1895] Fix | Delete
if 'answered' in labels:
[1896] Fix | Delete
message.add_flag('A')
[1897] Fix | Delete
elif isinstance(message, MHMessage):
[1898] Fix | Delete
labels = set(self.get_labels())
[1899] Fix | Delete
if 'unseen' in labels:
[1900] Fix | Delete
message.add_sequence('unseen')
[1901] Fix | Delete
if 'answered' in labels:
[1902] Fix | Delete
message.add_sequence('replied')
[1903] Fix | Delete
elif isinstance(message, BabylMessage):
[1904] Fix | Delete
message.set_visible(self.get_visible())
[1905] Fix | Delete
for label in self.get_labels():
[1906] Fix | Delete
message.add_label(label)
[1907] Fix | Delete
elif isinstance(message, Message):
[1908] Fix | Delete
pass
[1909] Fix | Delete
else:
[1910] Fix | Delete
raise TypeError('Cannot convert to specified type: %s' %
[1911] Fix | Delete
type(message))
[1912] Fix | Delete
[1913] Fix | Delete
[1914] Fix | Delete
class MMDFMessage(_mboxMMDFMessage):
[1915] Fix | Delete
"""Message with MMDF-specific properties."""
[1916] Fix | Delete
[1917] Fix | Delete
[1918] Fix | Delete
class _ProxyFile:
[1919] Fix | Delete
"""A read-only wrapper of a file."""
[1920] Fix | Delete
[1921] Fix | Delete
def __init__(self, f, pos=None):
[1922] Fix | Delete
"""Initialize a _ProxyFile."""
[1923] Fix | Delete
self._file = f
[1924] Fix | Delete
if pos is None:
[1925] Fix | Delete
self._pos = f.tell()
[1926] Fix | Delete
else:
[1927] Fix | Delete
self._pos = pos
[1928] Fix | Delete
[1929] Fix | Delete
def read(self, size=None):
[1930] Fix | Delete
"""Read bytes."""
[1931] Fix | Delete
return self._read(size, self._file.read)
[1932] Fix | Delete
[1933] Fix | Delete
def read1(self, size=None):
[1934] Fix | Delete
"""Read bytes."""
[1935] Fix | Delete
return self._read(size, self._file.read1)
[1936] Fix | Delete
[1937] Fix | Delete
def readline(self, size=None):
[1938] Fix | Delete
"""Read a line."""
[1939] Fix | Delete
return self._read(size, self._file.readline)
[1940] Fix | Delete
[1941] Fix | Delete
def readlines(self, sizehint=None):
[1942] Fix | Delete
"""Read multiple lines."""
[1943] Fix | Delete
result = []
[1944] Fix | Delete
for line in self:
[1945] Fix | Delete
result.append(line)
[1946] Fix | Delete
if sizehint is not None:
[1947] Fix | Delete
sizehint -= len(line)
[1948] Fix | Delete
if sizehint <= 0:
[1949] Fix | Delete
break
[1950] Fix | Delete
return result
[1951] Fix | Delete
[1952] Fix | Delete
def __iter__(self):
[1953] Fix | Delete
"""Iterate over lines."""
[1954] Fix | Delete
while True:
[1955] Fix | Delete
line = self.readline()
[1956] Fix | Delete
if not line:
[1957] Fix | Delete
return
[1958] Fix | Delete
yield line
[1959] Fix | Delete
[1960] Fix | Delete
def tell(self):
[1961] Fix | Delete
"""Return the position."""
[1962] Fix | Delete
return self._pos
[1963] Fix | Delete
[1964] Fix | Delete
def seek(self, offset, whence=0):
[1965] Fix | Delete
"""Change position."""
[1966] Fix | Delete
if whence == 1:
[1967] Fix | Delete
self._file.seek(self._pos)
[1968] Fix | Delete
self._file.seek(offset, whence)
[1969] Fix | Delete
self._pos = self._file.tell()
[1970] Fix | Delete
[1971] Fix | Delete
def close(self):
[1972] Fix | Delete
"""Close the file."""
[1973] Fix | Delete
if hasattr(self, '_file'):
[1974] Fix | Delete
try:
[1975] Fix | Delete
if hasattr(self._file, 'close'):
[1976] Fix | Delete
self._file.close()
[1977] Fix | Delete
finally:
[1978] Fix | Delete
del self._file
[1979] Fix | Delete
[1980] Fix | Delete
def _read(self, size, read_method):
[1981] Fix | Delete
"""Read size bytes using read_method."""
[1982] Fix | Delete
if size is None:
[1983] Fix | Delete
size = -1
[1984] Fix | Delete
self._file.seek(self._pos)
[1985] Fix | Delete
result = read_method(size)
[1986] Fix | Delete
self._pos = self._file.tell()
[1987] Fix | Delete
return result
[1988] Fix | Delete
[1989] Fix | Delete
def __enter__(self):
[1990] Fix | Delete
"""Context management protocol support."""
[1991] Fix | Delete
return self
[1992] Fix | Delete
[1993] Fix | Delete
def __exit__(self, *exc):
[1994] Fix | Delete
self.close()
[1995] Fix | Delete
[1996] Fix | Delete
def readable(self):
[1997] Fix | Delete
return self._file.readable()
[1998] Fix | Delete
[1999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function