• Home
  • Raw
  • Download

Lines Matching +full:path +full:- +full:key

37     def __init__(self, path, factory=None, create=True):  argument
39 self._path = os.path.abspath(os.path.expanduser(path))
43 """Add message and return assigned key."""
46 def remove(self, key): argument
50 def __delitem__(self, key): argument
51 self.remove(key)
53 def discard(self, key): argument
56 self.remove(key)
60 def __setitem__(self, key, message): argument
64 def get(self, key, default=None): argument
67 return self.__getitem__(key)
71 def __getitem__(self, key): argument
74 return self.get_message(key)
76 with contextlib.closing(self.get_file(key)) as file:
79 def get_message(self, key): argument
83 def get_string(self, key): argument
88 return email.message_from_bytes(self.get_bytes(key)).as_string()
90 def get_bytes(self, key): argument
94 def get_file(self, key): argument
95 """Return a file-like representation or raise a KeyError."""
108 for key in self.iterkeys():
110 value = self[key]
123 """Return an iterator over (key, message) tuples."""
124 for key in self.iterkeys():
126 value = self[key]
129 yield (key, value)
132 """Return a list of (key, message) tuples. Memory intensive."""
135 def __contains__(self, key): argument
145 for key in self.keys():
146 self.discard(key)
148 def pop(self, key, default=None): argument
151 result = self[key]
154 self.discard(key)
158 """Delete an arbitrary (key, message) pair and return it."""
159 for key in self.iterkeys():
160 return (key, self.pop(key)) # This is only run once.
173 for key, message in source:
175 self[key] = message
179 raise KeyError('No message with key(s)')
204 raise ValueError("String input must be ASCII-only; "
248 line = line[:-2] + b'\n'
250 line = line[:-1] + b'\n'
268 """A qmail-style Maildir mailbox."""
276 'tmp': os.path.join(self._path, 'tmp'),
277 'new': os.path.join(self._path, 'new'),
278 'cur': os.path.join(self._path, 'cur'),
280 if not os.path.exists(self._path):
283 for path in self._paths.values():
284 os.mkdir(path, 0o700)
293 """Add message and return assigned key."""
310 uniq = os.path.basename(tmp_file.name).split(self.colon)[0]
311 dest = os.path.join(self._path, subdir, uniq + suffix)
314 (os.path.getatime(tmp_file.name), message.get_date()))
334 def remove(self, key): argument
336 os.remove(os.path.join(self._path, self._lookup(key)))
338 def discard(self, key): argument
342 self.remove(key)
346 def __setitem__(self, key, message): argument
348 old_subpath = self._lookup(key)
357 subdir = os.path.dirname(dominant_subpath)
359 suffix = self.colon + dominant_subpath.split(self.colon)[-1]
362 self.discard(key)
363 tmp_path = os.path.join(self._path, temp_subpath)
364 new_path = os.path.join(self._path, subdir, key + suffix)
367 (os.path.getatime(tmp_path), message.get_date()))
373 def get_message(self, key): argument
375 subpath = self._lookup(key)
376 with open(os.path.join(self._path, subpath), 'rb') as f:
381 subdir, name = os.path.split(subpath)
384 msg.set_info(name.split(self.colon)[-1])
385 msg.set_date(os.path.getmtime(os.path.join(self._path, subpath)))
388 def get_bytes(self, key): argument
390 with open(os.path.join(self._path, self._lookup(key)), 'rb') as f:
393 def get_file(self, key): argument
394 """Return a file-like representation or raise a KeyError."""
395 f = open(os.path.join(self._path, self._lookup(key)), 'rb')
401 for key in self._toc:
403 self._lookup(key)
406 yield key
408 def __contains__(self, key): argument
411 return key in self._toc
441 os.path.isdir(os.path.join(self._path, entry)):
447 return Maildir(os.path.join(self._path, '.' + folder),
453 path = os.path.join(self._path, '.' + folder)
454 result = Maildir(path, factory=self._factory)
455 maildirfolder_path = os.path.join(path, 'maildirfolder')
456 if not os.path.exists(maildirfolder_path):
463 path = os.path.join(self._path, '.' + folder)
464 for entry in os.listdir(os.path.join(path, 'new')) + \
465 os.listdir(os.path.join(path, 'cur')):
468 for entry in os.listdir(path):
470 os.path.isdir(os.path.join(path, entry)):
473 for root, dirs, files in os.walk(path, topdown=False):
475 os.remove(os.path.join(root, entry))
477 os.rmdir(os.path.join(root, entry))
478 os.rmdir(path)
483 for entry in os.listdir(os.path.join(self._path, 'tmp')):
484 path = os.path.join(self._path, 'tmp', entry)
485 if now - os.path.getatime(path) > 129600: # 60 * 60 * 36
486 os.remove(path)
500 path = os.path.join(self._path, 'tmp', uniq)
502 os.stat(path)
506 return _create_carefully(path)
512 path)
517 # we have to unconditionally re-read the mailbox just in case it has
518 # been modified, because os.path.mtime() has a 2 sec resolution in the
520 # results in a few unnecessary re-reads when _refresh() is called
522 # will only re-read as needed. Because the filesystem might be being
529 if time.time() - self._last_read > 2 + self._skewfactor:
532 mtime = os.path.getmtime(self._paths[subdir])
541 path = self._paths[subdir]
542 for entry in os.listdir(path):
543 p = os.path.join(path, entry)
544 if os.path.isdir(p):
547 self._toc[uniq] = os.path.join(subdir, entry)
550 def _lookup(self, key): argument
551 """Use TOC to return subpath for given key, or raise a KeyError."""
553 if os.path.exists(os.path.join(self._path, self._toc[key])):
554 return self._toc[key]
559 return self._toc[key]
561 raise KeyError('No message with key: %s' % key) from None
565 """Return the next message in a one-time iteration."""
578 """A single-file mailbox."""
580 def __init__(self, path, factory=None, create=True): argument
581 """Initialize a single-file mailbox."""
582 Mailbox.__init__(self, path, factory, create)
604 """Add message and return assigned key."""
611 return self._next_key - 1
613 def remove(self, key): argument
615 self._lookup(key)
616 del self._toc[key]
619 def __setitem__(self, key, message): argument
621 self._lookup(key)
622 self._toc[key] = self._append_message(message)
630 def __contains__(self, key): argument
633 return key in self._toc
680 for key in sorted(self._toc.keys()):
681 start, stop = self._toc[key]
687 stop - self._file.tell()))
691 new_toc[key] = (new_start, new_file.tell())
739 def _lookup(self, key=None): argument
743 if key is not None:
745 return self._toc[key]
747 raise KeyError('No message with key: %s' % key) from None
777 def get_message(self, key): argument
779 start, stop = self._lookup(key)
782 string = self._file.read(stop - self._file.tell())
787 def get_string(self, key, from_=False): argument
790 self.get_bytes(key, from_)).as_string(unixfrom=from_)
792 def get_bytes(self, key, from_=False): argument
794 start, stop = self._lookup(key)
798 string = self._file.read(stop - self._file.tell())
801 def get_file(self, key, from_=False): argument
802 """Return a file-like representation or raise a KeyError."""
803 start, stop = self._lookup(key)
816 if newline != -1:
830 from_line = b'From MAILER-DAEMON ' + time.asctime(time.gmtime()).encode()
847 def __init__(self, path, factory=None, create=True): argument
850 _mboxMMDF.__init__(self, path, factory, create)
857 """Generate key-to-(start, stop) table of contents."""
867 stops.append(line_pos - len(linesep))
877 stops.append(line_pos - len(linesep))
893 def __init__(self, path, factory=None, create=True): argument
896 _mboxMMDF.__init__(self, path, factory, create)
907 """Generate key-to-(start, stop) table of contents."""
922 stops.append(line_pos - len(linesep))
938 def __init__(self, path, factory=None, create=True): argument
940 Mailbox.__init__(self, path, factory, create)
941 if not os.path.exists(self._path):
944 os.close(os.open(os.path.join(self._path, '.mh_sequences'),
951 """Add message and return assigned key."""
957 new_path = os.path.join(self._path, str(new_key))
984 def remove(self, key): argument
986 path = os.path.join(self._path, str(key))
988 f = open(path, 'rb+')
991 raise KeyError('No message with key: %s' % key)
996 os.remove(path)
998 def __setitem__(self, key, message): argument
1000 path = os.path.join(self._path, str(key))
1002 f = open(path, 'rb+')
1005 raise KeyError('No message with key: %s' % key)
1012 os.close(os.open(path, os.O_WRONLY | os.O_TRUNC))
1015 self._dump_sequences(message, key)
1022 def get_message(self, key): argument
1026 f = open(os.path.join(self._path, str(key)), 'rb+')
1028 f = open(os.path.join(self._path, str(key)), 'rb')
1031 raise KeyError('No message with key: %s' % key)
1043 if key in key_list:
1047 def get_bytes(self, key): argument
1051 f = open(os.path.join(self._path, str(key)), 'rb+')
1053 f = open(os.path.join(self._path, str(key)), 'rb')
1056 raise KeyError('No message with key: %s' % key)
1068 def get_file(self, key): argument
1069 """Return a file-like representation or raise a KeyError."""
1071 f = open(os.path.join(self._path, str(key)), 'rb')
1074 raise KeyError('No message with key: %s' % key)
1084 def __contains__(self, key): argument
1086 return os.path.exists(os.path.join(self._path, str(key)))
1095 self._file = open(os.path.join(self._path, '.mh_sequences'), 'rb+')
1120 if os.path.isdir(os.path.join(self._path, entry)):
1126 return MH(os.path.join(self._path, folder),
1131 return MH(os.path.join(self._path, folder),
1136 path = os.path.join(self._path, folder)
1137 entries = os.listdir(path)
1139 os.remove(os.path.join(path, '.mh_sequences'))
1144 os.rmdir(path)
1147 """Return a name-to-key-list dictionary to define each sequence."""
1149 with open(os.path.join(self._path, '.mh_sequences'), 'r', encoding='ASCII') as f:
1159 start, stop = (int(x) for x in spec.split('-'))
1161 results[name] = [key for key in sorted(keys) \
1162 if key in all_keys]
1171 """Set sequences using the given name-to-key-list dictionary."""
1172 f = open(os.path.join(self._path, '.mh_sequences'), 'r+', encoding='ASCII')
1181 for key in sorted(set(keys)):
1182 if key - 1 == prev:
1185 f.write('-')
1188 f.write('%s %s' % (prev, key))
1190 f.write(' %s' % key)
1191 prev = key
1200 """Re-name messages to eliminate numbering gaps. Invalidates keys."""
1204 for key in self.iterkeys():
1205 if key - 1 != prev:
1206 changes.append((key, prev + 1))
1208 os.link(os.path.join(self._path, str(key)),
1209 os.path.join(self._path, str(prev + 1)))
1211 os.rename(os.path.join(self._path, str(key)),
1212 os.path.join(self._path, str(prev + 1)))
1214 os.unlink(os.path.join(self._path, str(key)))
1225 def _dump_sequences(self, message, key): argument
1231 key_list.append(key)
1232 elif key in key_list:
1233 del key_list[key_list.index(key)]
1236 all_sequences[sequence] = [key]
1241 """An Rmail-style Babyl mailbox."""
1246 def __init__(self, path, factory=None, create=True): argument
1248 _singlefileMailbox.__init__(self, path, factory, create)
1252 """Add message and return assigned key."""
1253 key = _singlefileMailbox.add(self, message)
1255 self._labels[key] = message.get_labels()
1256 return key
1258 def remove(self, key): argument
1260 _singlefileMailbox.remove(self, key)
1261 if key in self._labels:
1262 del self._labels[key]
1264 def __setitem__(self, key, message): argument
1266 _singlefileMailbox.__setitem__(self, key, message)
1268 self._labels[key] = message.get_labels()
1270 def get_message(self, key): argument
1272 start, stop = self._lookup(key)
1288 n = stop - self._file.tell()
1294 if key in self._labels:
1295 msg.set_labels(self._labels[key])
1298 def get_bytes(self, key): argument
1300 start, stop = self._lookup(key)
1314 n = stop - self._file.tell()
1320 def get_file(self, key): argument
1321 """Return a file-like representation or raise a KeyError."""
1322 return io.BytesIO(self.get_bytes(key).replace(b'\n', linesep))
1325 """Return a list of user-defined labels in the mailbox."""
1334 """Generate key-to-(start, stop) table of contents."""
1345 stops.append(line_pos - len(linesep))
1353 stops.append(line_pos - len(linesep))
1355 stops.append(line_pos - len(linesep))
1441 if body_start - 2 != -1:
1460 line = line[:-2] + b'\n'
1462 line = line[:-1] + b'\n'
1477 line = line[:-2] + linesep
1479 line = line[:-1] + linesep
1481 line = line[:-1] + linesep
1490 """Message with mailbox-format-specific properties."""
1512 """Assume the non-format-specific state of message."""
1519 """Copy format-specific state to message insofar as possible."""
1521 return # There's nothing format-specific to explain.
1527 """Message with Maildir-specific properties."""
1567 self.set_flags(''.join(set(self.get_flags()) - set(flag)))
1592 """Copy Maildir-specific state to message insofar as possible."""
1609 message.set_from('MAILER-DAEMON', time.gmtime(self.get_date()))
1636 """Message with mbox- or MMDF-specific properties."""
1642 self.set_from('MAILER-DAEMON', True)
1663 return self.get('Status', '') + self.get('X-Status', '')
1683 self.replace_header('X-Status', xstatus_flags)
1685 self.add_header('X-Status', xstatus_flags)
1693 if 'Status' in self or 'X-Status' in self:
1694 self.set_flags(''.join(set(self.get_flags()) - set(flag)))
1697 """Copy mbox- or MMDF-specific state to message insofar as possible."""
1711 del message['x-status']
1712 maybe_date = ' '.join(self.get_from().split()[-5:])
1730 del message['x-status']
1740 del message['x-status']
1749 """Message with mbox-specific properties."""
1753 """Message with MH-specific properties."""
1786 """Copy MH-specific state to message insofar as possible."""
1825 """Message with Babyl-specific properties."""
1873 for header in ('Date', 'From', 'Reply-To', 'To', 'CC', 'Subject'):
1878 """Copy Babyl-specific state to message insofar as possible."""
1920 """Message with MMDF-specific properties."""
1924 """A read-only wrapper of a file."""
1952 sizehint -= len(line)
1988 size = -1
2025 """A read-only wrapper of part of a file."""
2035 return _ProxyFile.tell(self) - self._start
2049 remaining = self._stop - self._pos
2109 if os.path.exists(f.name + '.lock'):
2112 def _create_carefully(path): argument
2114 fd = os.open(path, os.O_CREAT | os.O_EXCL | os.O_RDWR, 0o666)
2116 return open(path, 'rb+')
2120 def _create_temporary(path): argument
2121 """Create a temp file based on path and open for reading and writing."""
2122 return _create_carefully('%s.%s.%s.%s' % (path, int(time.time()),
2139 """Raised for module-specific errors."""