rem stringlengths 0 322k | add stringlengths 0 2.05M | context stringlengths 8 228k |
|---|---|---|
if not unix_from: | if unix_from: msg_has_mbox_format = True else: msg_has_mbox_format = False | def write(self, msg): """Write a rfc822 message object to the 'mbox' mailbox. If the rfc822 has no Unix 'From_' line, then one is constructed from other headers in the message. |
if options.mangle_from: | if (not msg_has_mbox_format) and options.mangle_from: | def write(self, msg): """Write a rfc822 message object to the 'mbox' mailbox. If the rfc822 has no Unix 'From_' line, then one is constructed from other headers in the message. |
self.mbox_file.write(os.linesep) | if not msg_has_mbox_format: self.mbox_file.write(os.linesep) | def write(self, msg): """Write a rfc822 message object to the 'mbox' mailbox. If the rfc822 has no Unix 'From_' line, then one is constructed from other headers in the message. |
address_header = message.get('header') | address_header = message.get(header) | def guess_return_path(message): """Return a guess at the Return Path address of an rfc822 message""" assert(message) for header in ('Return-path', 'From'): address_header = message.get('header') if address_header: (name, address) = rfc822.parseaddr(address_header) if address: return address # argh, we can't find any v... |
(None, last_dir) = os.path.split(os.path.dirname(message.fp.name)) | last_dir = os.path.basename(os.path.dirname(message.fp.name)) | def add_status_headers(message): """ Add Status and X-Status headers to a message from a maildir mailbox. Maildir messages store their information about being read/replied/etc in the suffix of the filename rather than in Status and X-Status headers in the message. In order to archive maildir messages into mbox format,... |
self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) | days_old_max = 180 self.mbox_name = make_mbox(messages=3, hours_old=(24 * (days_old_max+1))) | def testSuffix(self): """archiving with specified --suffix arguments""" for suffix in ("_static_", "_%B_%Y", "-%Y-%m-%d"): for execute in ("system_long", "system_short", "package"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_... |
parsed_suffix = time.strftime(suffix, time.localtime(time.time())) | parsed_suffix_time = time.time() - days_old_max*24*60*60 parsed_suffix = time.strftime(suffix, time.localtime(parsed_suffix_time)) | def testSuffix(self): """archiving with specified --suffix arguments""" for suffix in ("_static_", "_%B_%Y", "-%Y-%m-%d"): for execute in ("system_long", "system_short", "package"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_... |
imap_username, imap_str = imap_str.split(':', 1) imap_password, imap_str = imap_str.split('@', 1) | def _archive_imap(mailbox_name, final_archive_name): """Archive an imap mailbox - used by archive_mailbox()""" assert(mailbox_name) assert(final_archive_name) import imaplib import cStringIO import getpass archive = None stats = Stats(mailbox_name, final_archive_name) imap_str = mailbox_name[mailbox_name.find('://') +... | |
pass imap_username = getpass.getuser() | unexpected_error("you must provide a properly formatted \ IMAP connection string") | def _archive_imap(mailbox_name, final_archive_name): """Archive an imap mailbox - used by archive_mailbox()""" assert(mailbox_name) assert(final_archive_name) import imaplib import cStringIO import getpass archive = None stats = Stats(mailbox_name, final_archive_name) imap_str = mailbox_name[mailbox_name.find('://') +... |
imap_password = getpass.getpass() imap_server, imap_folder = imap_str.split('/', 1) | try: imap_username, imap_password = imap_username.split(':', 1) except: imap_password = getpass.getpass() | def _archive_imap(mailbox_name, final_archive_name): """Archive an imap mailbox - used by archive_mailbox()""" assert(mailbox_name) assert(final_archive_name) import imaplib import cStringIO import getpass archive = None stats = Stats(mailbox_name, final_archive_name) imap_str = mailbox_name[mailbox_name.find('://') +... |
output_dir = os.curdir | output_dir = None | def clean(self): """Delete any temporary files or lockfiles that exist""" if self.procmail_lock: vprint("removing stale procmail lock '%s'" % self.procmail_lock) try: os.remove(self.procmail_lock) except (IOError, OSError): pass if self.retain: vprint("removing stale retain file '%s'" % self.retain) try: os.remove(self... |
if not os.path.isdir(self.output_dir): user_error("output directory does not exist: '%s'" % \ self.output_dir) if not os.access(self.output_dir, os.W_OK): user_error("no write permission on output directory: '%s'" % \ self.output_dir) if is_world_writable(self.output_dir): unexpected_error(("output directory is world-w... | if self.output_dir: if not os.path.isdir(self.output_dir): user_error("output directory does not exist: '%s'" % \ self.output_dir) if not os.access(self.output_dir, os.W_OK): user_error("no write permission on output directory: '%s'" % \ self.output_dir) if is_world_writable(self.output_dir): unexpected_error(("output ... | def sanity_check(self): """Complain bitterly about our options now rather than later""" if not os.path.isdir(self.output_dir): user_error("output directory does not exist: '%s'" % \ self.output_dir) if not os.access(self.output_dir, os.W_OK): user_error("no write permission on output directory: '%s'" % \ self.output_di... |
tempfile.tempdir = _options.output_dir assert(tempfile.tempdir) | def main(args = sys.argv[1:]): global _stale usage = """Usage: %s [options] mailbox [mailbox...] | |
assert(mailbox_name) | assert(mailbox_name) final_archive_name = mailbox_name + _options.archive_suffix if _options.output_dir: final_archive_name = os.path.join(_options.output_dir, os.path.basename(final_archive_name)) vprint("archiving '%s' to '%s' ..." % (mailbox_name, final_archive_name)) tempfile.tempdir = choose_temp_dir(mailbox_nam... | def archive(mailbox_name): """Archives a mailbox. Arguments: mailbox_name -- the filename/dirname of the mailbox to be archived final_archive_name -- the filename of the 'mbox' mailbox to archive old messages to - appending if the archive already exists """ assert(mailbox_name) vprint("set tempfile directory to '%s'... |
final_archive_name = mailbox_name + _options.archive_suffix final_archive_name = os.path.join(_options.output_dir, os.path.basename(final_archive_name)) vprint("archiving '%s' to '%s' ..." % (mailbox_name, final_archive_name)) | def archive(mailbox_name): """Archives a mailbox. Arguments: mailbox_name -- the filename/dirname of the mailbox to be archived final_archive_name -- the filename of the 'mbox' mailbox to archive old messages to - appending if the archive already exists """ assert(mailbox_name) vprint("set tempfile directory to '%s'... | |
imap_server, imap_folder = imap_str.split('/', 1) | def _archive_imap(mailbox_name, final_archive_name): """Archive an imap mailbox - used by archive_mailbox()""" assert(mailbox_name) assert(final_archive_name) import imaplib import cStringIO import getpass archive = None stats = Stats(mailbox_name, final_archive_name) imap_str = mailbox_name[mailbox_name.find('://') +... | |
unexpected_error("you must provide a properly formatted \ IMAP connection string") | pass | def _archive_imap(mailbox_name, final_archive_name): """Archive an imap mailbox - used by archive_mailbox()""" assert(mailbox_name) assert(final_archive_name) import imaplib import cStringIO import getpass archive = None stats = Stats(mailbox_name, final_archive_name) imap_str = mailbox_name[mailbox_name.find('://') +... |
cram_md5 = True if cram_md5: | try: | def _archive_imap(mailbox_name, final_archive_name): """Archive an imap mailbox - used by archive_mailbox()""" assert(mailbox_name) assert(final_archive_name) import imaplib import cStringIO import getpass archive = None stats = Stats(mailbox_name, final_archive_name) imap_str = mailbox_name[mailbox_name.find('://') +... |
else: | except: | def _archive_imap(mailbox_name, final_archive_name): """Archive an imap mailbox - used by archive_mailbox()""" assert(mailbox_name) assert(final_archive_name) import imaplib import cStringIO import getpass archive = None stats = Stats(mailbox_name, final_archive_name) imap_str = mailbox_name[mailbox_name.find('://') +... |
self.assertEqual(archivemail.options.quiet, 0) | self.assertEqual(archivemail.options.delete_old_mail, 0) | def testDeleteOldMail(self): """we should not delete old mail by default""" self.assertEqual(archivemail.options.quiet, 0) |
self.mbox.exclusive_lock() | if not hasattr(os, 'fork'): return pid = os.fork() if pid == 0: self.mbox.exclusive_lock() time.sleep(2) self.mbox.exclusive_unlock() os._exit(0) time.sleep(0.5) | def testExclusiveLock(self): """exclusive_lock/unlock should create/delete an advisory lock""" self.mbox.exclusive_lock() file = open(self.mbox_name, "r+") lock_nb = fcntl.LOCK_EX | fcntl.LOCK_NB self.assertRaises(IOError, fcntl.flock, file.fileno(), lock_nb) |
self.assertRaises(IOError, fcntl.flock, file.fileno(), lock_nb) self.mbox.exclusive_unlock() fcntl.flock(file.fileno(), lock_nb) fcntl.flock(file.fileno(), fcntl.LOCK_UN) | fd = file.fileno() try: self.assertRaises(IOError, fcntl.flock, fd, lock_nb) finally: exited_pid, status = os.waitpid(pid, 0) fcntl.flock(fd, lock_nb) fcntl.flock(fd, fcntl.LOCK_UN) | def testExclusiveLock(self): """exclusive_lock/unlock should create/delete an advisory lock""" self.mbox.exclusive_lock() file = open(self.mbox_name, "r+") lock_nb = fcntl.LOCK_EX | fcntl.LOCK_NB self.assertRaises(IOError, fcntl.flock, file.fileno(), lock_nb) |
"filter-append", "pwfile", | "filter-append=", "pwfile=", | def parse_args(self, args, usage): """Set our runtime options from the command-line arguments. |
while os.path.isfile(lock_name): vprint("lockfile '%s' exists - sleeping..." % lock_name) time.sleep(options.lockfile_sleep) attempt = attempt + 1 if (attempt >= options.lockfile_attempts): unexpected_error("Giving up waiting for procmail lock '%s'" % lock_name) vprint("writing lockfile '%s'" % lock_name) old_umask = o... | try: while True: attempt = attempt + 1 try: os.link(prelock_name, lock_name) break except OSError, e: if os.fstat(plfd)[stat.ST_NLINK] == 2: break if e.errno != errno.EEXIST: raise if (attempt >= options.lockfile_attempts): unexpected_error("Giving up waiting for " "procmail lock '%s'" % lock_name) vprint("lockfi... | def procmail_lock(self): """Create a procmail lockfile on the 'mbox' mailbox""" lock_name = self.mbox_file_name + options.lockfile_extension attempt = 0 while os.path.isfile(lock_name): vprint("lockfile '%s' exists - sleeping..." % lock_name) time.sleep(options.lockfile_sleep) attempt = attempt + 1 if (attempt >= optio... |
lock.close() old_umask = os.umask(old_umask) | vprint("acquired lockfile '%s'" % lock_name) | def procmail_lock(self): """Create a procmail lockfile on the 'mbox' mailbox""" lock_name = self.mbox_file_name + options.lockfile_extension attempt = 0 while os.path.isfile(lock_name): vprint("lockfile '%s' exists - sleeping..." % lock_name) time.sleep(options.lockfile_sleep) attempt = attempt + 1 if (attempt >= optio... |
archivemail.options.quiet = 1 | def testOld(self): """archiving an old mailbox""" for execute in ("package", "system"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_name) if execute == "package": archivem... | |
archivemail.options.quiet = 1 | def testMixed(self): """archiving a mixed mailbox""" for execute in ("package", "system"): self.new_mbox = make_mbox(messages=3, hours_old=(24 * 179)) self.old_mbox = make_mbox(messages=3, hours_old=(24 * 181)) self.mbox_name = tempfile.mktemp() shutil.copyfile(self.new_mbox, self.mbox_name) append_file(self.old_mbox, ... | |
archivemail.options.quiet = 1 | def testNew(self): """archiving a new mailbox""" for execute in ("package", "system"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 179)) self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_name) if execute == "package": archivema... | |
archivemail.options.quiet = 1 | def testOldExisting(self): """archiving an old mailbox with an existing archive""" for execute in ("package", "system"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] self.copy_name = tempfile.mktemp() archive_name = self.mbox_name + "_archive" shuti... | |
archivemail.options.quiet = 1 | def testNew(self): """mbox timestamps should not change after no archival""" for execute in ("package", "system"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 179)) self.mtime = os.path.getmtime(self.mbox_name) - 66 self.atime = os.path.getatime(self.mbox_name) - 88 os.utime(self.mbox_name, (self.atime, self... | |
archivemail.options.quiet = 1 | def testMixed(self): """mbox timestamps should not change after semi-archival""" for execute in ("package", "system"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) self.mtime = os.path.getmtime(self.mbox_name) - 66 self.atime = os.path.getatime(self.mbox_name) - 88 os.utime(self.mbox_name, (self.atime, ... | |
archivemail.options.quiet = 1 | def testOld(self): """mbox timestamps should not change after archival""" for execute in ("package", "system"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) self.mtime = os.path.getmtime(self.mbox_name) - 66 self.atime = os.path.getatime(self.mbox_name) - 88 os.utime(self.mbox_name, (self.atime, self.mt... | |
archivemail.options.quiet = 1 archivemail.options.preserve_unread = 1 | def testOldRead(self): """archiving an old read mailbox should create an archive""" for execute in ("package", "system_long", "system_short"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181), \ headers={"Status":"RO"}) self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_name) if exe... | |
archivemail.options.quiet = 1 archivemail.options.preserve_unread = 1 | def testOldUnread(self): """archiving an unread mailbox should not create an archive""" for execute in ("package", "system_long", "system_short"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_name) if execute == "package": arch... | |
archivemail.options.quiet = 1 | def testSuffix(self): """archiving with specified --suffix arguments""" for suffix in ("_static_", "_%B_%Y", "-%Y-%m-%d"): for execute in ("system_long", "system_short", "package"): days_old_max = 180 self.mbox_name = make_mbox(messages=3, hours_old=(24 * (days_old_max+1))) self.copy_name = tempfile.mktemp() shutil.cop... | |
archivemail.options.quiet = 1 archivemail.options.dry_run = 1 | def testOld(self): """archiving an old mailbox with the 'dry-run' option""" for execute in ("package", "system_long", "system_short"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_name) if execute == "package": archivemail.opti... | |
archivemail.options.quiet = 1 | def testOld(self): """specifying the 'days' option on an older mailbox""" for execute in ("package", "system", "system_long"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 12)) self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_name) if execute == "package": archivemail.options.quiet... | |
archivemail.options.quiet = 1 | def testNew(self): """specifying the 'days' option on a newer mailbox""" for execute in ("package", "system", "system_long"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 10)) self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_name) if execute == "package": archivemail.options.quiet ... | |
archivemail.options.quiet = 1 archivemail.options.delete_old_mail = 1 | def testNew(self): """archiving a new mailbox with the 'delete' option""" for execute in ("package", "system"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 179)) self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_name) if execute == "package": archivemail.options.quiet = 1 archivema... | |
archivemail.options.delete_old_mail = 1 archivemail.options.quiet = 1 | def testMixed(self): """archiving a mixed mailbox with the 'delete' option""" for execute in ("package", "system"): self.new_mbox = make_mbox(messages=3, hours_old=(24 * 179)) self.old_mbox = make_mbox(messages=3, hours_old=(24 * 181)) self.mbox_name = tempfile.mktemp() shutil.copyfile(self.new_mbox, self.mbox_name) ap... | |
archivemail.options.quiet = 1 archivemail.options.delete_old_mail = 1 | def testOld(self): """archiving an old mailbox with the 'delete' option""" for execute in ("package", "system"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_name) if execute == "package": archivemail.options.quiet = 1 archivem... | |
archivemail.options.quiet = 1 | def testOld(self): """by default, old flagged messages should not be archived""" for execute in ("system", "package"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181), \ headers={"X-Status":"F"}) self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_name) if execute == "package": arch... | |
archivemail.options.quiet = 1 | def testIncludeFlaggedNew(self): """new flagged messages should not be archived with include_flagged""" for execute in ("system", "package"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 179), \ headers={"X-Status":"F"}) self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_name) if exe... | |
archivemail.options.quiet = 1 | def testIncludeFlaggedOld(self): """old flagged messages should be archived with include_flagged""" for execute in ("system", "package"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181), \ headers={"X-Status":"F"}) self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_name) if execute... | |
archivemail.options.quiet = 1 | def testOld(self): """archiving an old mailbox with a sepecified output dir""" for execute in ("package", "system_long", "system_short"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_name) self.dir_name = tempfile.mktemp() os.m... | |
archivemail.options.no_compress = 1 archivemail.options.quiet = 1 | def testOld(self): """archiving an old mailbox uncompressed""" for execute in ("package", "system"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_name) if execute == "packa... | |
archivemail.options.no_compress = 1 archivemail.options.quiet = 1 | def testNew(self): """archiving a new mailbox uncompressed""" for execute in ("package", "system"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 179)) self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_name) if execute == "packag... | |
archivemail.options.no_compress = 1 archivemail.options.quiet = 1 | def testMixed(self): """archiving a mixed mailbox uncompressed""" for execute in ("package", "system"): self.new_mbox = make_mbox(messages=3, hours_old=(24 * 179)) self.old_mbox = make_mbox(messages=3, hours_old=(24 * 181)) self.mbox_name = tempfile.mktemp() shutil.copyfile(self.new_mbox, self.mbox_name) append_file(se... | |
archivemail.options.no_compress = 1 archivemail.options.quiet = 1 | def testOldExists(self): """archiving an old mailbox uncopressed with an existing archive""" for execute in ("package", "system"): self.mbox_name = make_mbox(messages=3, hours_old=(24 * 181)) self.mbox_mode = os.stat(self.mbox_name)[stat.ST_MODE] self.copy_name = tempfile.mktemp() archive_name = self.mbox_name + "_arch... | |
archivemail.options.quiet = 1 | def testSmaller(self): """giving a size argument smaller than the message""" for execute in ("package", "system_long", "system_short"): self.mbox_name = make_mbox(messages=1, hours_old=(24 * 181)) size_arg = os.path.getsize(self.mbox_name) - 1 self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy... | |
archivemail.options.quiet = 1 | def testBigger(self): """giving a size argument bigger than the message""" for execute in ("package", "system_long", "system_short"): self.mbox_name = make_mbox(messages=1, hours_old=(24 * 181)) size_arg = os.path.getsize(self.mbox_name) + 1 self.copy_name = tempfile.mktemp() shutil.copyfile(self.mbox_name, self.copy_n... | |
archivemail.options.quiet = 1 | def testOld(self): """after archiving, the original mbox mode should be preserved""" for mode in (0666, 0664, 0660, 0640, 0600): for execute in ("package", "system"): self.mbox_name = make_mbox(messages=1, hours_old=(24 * 181)) os.chmod(self.mbox_name, mode) if execute == "package": archivemail.options.quiet = 1 archiv... | |
archivemail.options.quiet = 1 | def testNew(self): """after no archiving, the original mbox mode should be preserved""" for mode in (0666, 0664, 0660, 0640, 0600): for execute in ("package", "system"): self.mbox_name = make_mbox(messages=1, hours_old=(24 * 179)) os.chmod(self.mbox_name, mode) if execute == "package": archivemail.options.quiet = 1 arc... | |
scripts=["archivemail"], | scripts=["archivemail.py"], | def check_python_version(): """Abort if we are running on python < v2.0""" too_old_error = """This program requires python v2.0 or greater. |
self.temproot = tempfile.tempdir = tempfile.mkdtemp() | self.temproot = tempfile.tempdir = \ tempfile.mkdtemp(prefix="test-archivemail") | def setUp(self): if not self.temproot: assert(not tempfile.tempdir) self.temproot = tempfile.tempdir = tempfile.mkdtemp() |
vprint("Deleting messages") imap_srv.store(string.join(message_list, ','), '+FLAGS.SILENT', '\\Deleted') | vprint("Deleting %s messages" % len(message_list)) max_delete = 100 for i in range(0, len(message_list), max_delete): imap_srv.store(string.join(message_list[i:i+max_delete], ','), '+FLAGS.SILENT', '\\Deleted') | def _archive_imap(mailbox_name, final_archive_name): """Archive an imap mailbox - used by archive_mailbox()""" assert(mailbox_name) assert(final_archive_name) import imaplib import cStringIO import getpass archive = None stats = Stats(mailbox_name, final_archive_name) imap_str = mailbox_name[mailbox_name.find('://') +... |
final_archive_name) | os.path.basename(final_archive_name)) | def archive(mailbox_name): """Archives a mailbox. Arguments: mailbox_name -- the filename/dirname of the mailbox to be archived final_archive_name -- the filename of the 'mbox' mailbox to archive old messages to - appending if the archive already exists """ tempfile.tempdir = choose_temp_dir(mailbox_name) vprint("set... |
filter.append("BIGGER %d" % options.min_size) | filter.append("LARGER %d" % options.min_size) | def build_imap_filter(): """Return an imap filter string""" filter = [] old = 0 if options.date_old_max == None: time_now = time.time() secs_old_max = (options.days_old_max * 24 * 60 * 60) time_old = time.gmtime(time_now - secs_old_max) time_str = time.strftime('%d-%b-%Y', time_old) filter.append("BEFORE %s" % time_st... |
self.script = script | def execute(self, script): """ Call this to execute a chunk of code. """ self.result = self.SUCCESS try: self.script = script self.setPathInfo() self._exec(script) except weblib.Finished: self.result = self.EXIT except AssertionError, e: self.result = self.FAILURE self.error = e except weblib.Redirect, e: #@TODO: get r... | |
self.execute(self.script) | self.execute(self.script) else: print self.result | def runScript(self): # self.result is None if nothing's been run yet # it would be error or exception if dotWeblibPy had a problem if (self.result is None) or (self.result == self.SUCCESS): self.execute(self.script) |
if str_i =="L": | if str_i[-1] =="L": | def __str__(self): n, p = self.n, self.p i, f = divmod(abs(n), _tento(p)) if p: # this snips off the trailing L.. (present in py1.52 but not 2.0) # -mwallace 0118.2001: frac = str(f) if frac[-1]=="L": frac = frac[:-1] frac = "0" * (p - len(frac)) + frac else: frac = "" # same for i: -mwallace str_i = str(i) if str_i ==... |
res = None | def _findmember(self, member): """ self._findmember(member) : does self define or inherit member? | |
for item in dir(ancestor): if item == member: res = ancestor.__dict__[member] break return res | if member in dir(ancestor): return ancestor.__dict__[member] return None | def _findmember(self, member): """ self._findmember(member) : does self define or inherit member? |
del cookie | def __init__(self, querystring=None, form=None, environ=None, method=None, cookie=None, engine=weblib, content=None, contentType=None): | |
if (content is not None) and (contentType is None): | if (self.content is not None) and (contentType is None): | def __init__(self, querystring=None, form=None, environ=None, method=None, cookie=None, engine=weblib, content=None, contentType=None): |
if (self.method=="POST") and (self.contentType[:10]=='multipart/'): | if (self.content) and (self.contentType[:10]=='multipart/'): | def __init__(self, querystring=None, form=None, environ=None, method=None, cookie=None, engine=weblib, content=None, contentType=None): |
self.model['shipToBilling']=(self.billData==self.shipData) | self.model['shipToBilling']=self.input.get('shipToBilling') \ or (self.billData==self.shipData) | def act_get_billing(self): import zebra self.consult(self.billData) self.model['shipToBilling']=(self.billData==self.shipData) zebra.show('frm_billing', self.model) |
self.next = "checkout" | def act_add_card(self): self.do("set_comments") | |
self.redirect(action = "checkout") | self.redirect(action = "confirm") | def act_add_card(self): self.do("set_comments") |
self.billData = None self.shipData = None self.cardData = None | self.billData = zikebase.Contact()._data.copy() self.shipData = zikebase.Contact()._data.copy() self.cardData = zikeshop.Card()._data.copy() | def act_show_receipt(self): assert self.data.get("saleID"), \ "No receipt to show." |
raise LookupError("fetch(%s, %s, **%s) didn't match anything!" % (klass, __ID__, kw)) | raise LookupError("matchOne(%s, *%s, **%s) didn't match anything!" % (klass, args, kw)) | def matchOne(self, klass, *args, **kwargs): res = self.match(klass, *args, **kwargs) if len(res)==0: raise LookupError("fetch(%s, %s, **%s) didn't match anything!" % (klass, __ID__, kw)) elif len(res)>1: raise LookupError("fetch(%s) matched multiple values!" % (klass, __ID__, kw)) return res[0] |
raise LookupError("fetch(%s) matched multiple values!" % (klass, __ID__, kw)) | raise LookupError("matchOne(%s, *%s, **%s) matched %s objects!" % (klass, args, kw, len(res))) | def matchOne(self, klass, *args, **kwargs): res = self.match(klass, *args, **kwargs) if len(res)==0: raise LookupError("fetch(%s, %s, **%s) didn't match anything!" % (klass, __ID__, kw)) elif len(res)>1: raise LookupError("fetch(%s) matched multiple values!" % (klass, __ID__, kw)) return res[0] |
eng = self | def runScript(self): eng = self # eng.result is None if nothing's been run yet # it would be error or exception if dotWeblibPy had a problem if (eng.result is None) or (eng.result == eng.SUCCESS): if os.path.exists(self.getScriptName()): eng.execute(open(self.getScriptName())) else: eng.stop() print "Status: 404" sys.e... | |
if (eng.result is None) or (eng.result == eng.SUCCESS): | if (self.result is None) or (self.result == self.SUCCESS): | def runScript(self): eng = self # eng.result is None if nothing's been run yet # it would be error or exception if dotWeblibPy had a problem if (eng.result is None) or (eng.result == eng.SUCCESS): if os.path.exists(self.getScriptName()): eng.execute(open(self.getScriptName())) else: eng.stop() print "Status: 404" sys.e... |
eng.execute(open(self.getScriptName())) | self.execute(open(self.getScriptName())) | def runScript(self): eng = self # eng.result is None if nothing's been run yet # it would be error or exception if dotWeblibPy had a problem if (eng.result is None) or (eng.result == eng.SUCCESS): if os.path.exists(self.getScriptName()): eng.execute(open(self.getScriptName())) else: eng.stop() print "Status: 404" sys.e... |
eng.stop() | self.stop() | def runScript(self): eng = self # eng.result is None if nothing's been run yet # it would be error or exception if dotWeblibPy had a problem if (eng.result is None) or (eng.result == eng.SUCCESS): if os.path.exists(self.getScriptName()): eng.execute(open(self.getScriptName())) else: eng.stop() print "Status: 404" sys.e... |
def sendError(eng): assert self.SITE_MAIL, "must define SITE_MAIL first!" | def sendError(self): SITE_MAIL = self.locals["SITE_MAIL"] SITE_NAME = self.locals["SITE_NAME"] assert SITE_MAIL is not None, "must define SITE_MAIL first!" | def sendError(eng): assert self.SITE_MAIL, "must define SITE_MAIL first!" hr = "-" * 50 + "\n" msg = weblib.trim( """ To: %s From: weblib.cgi <%s> Subject: uncaught exception in %s |
""" % (self.SITE_MAIL, self.SITE_MAIL, self.SITE_NAME)) msg = msg + "uncaught exception in %s\n\n" % self.getScriptName() msg = msg + hr msg = msg + self.error msg = msg + hr msg = msg + "FORM: %s\n" % self.request.form msg = msg + "QUERYSTRING: %s\n" % self.request.querystring msg = msg + "COOKIE: %s\n" % self.reques... | """ % (SITE_MAIL, SITE_MAIL, SITE_NAME)) msg += "uncaught exception in %s\n\n" % self.getScriptName() msg += hr msg += self.error msg += hr msg += "FORM: %s\n" % self.request.form msg += "QUERYSTRING: %s\n" % self.request.querystring msg += "COOKIE: %s\n" % self.request.cookie if hasattr(self, "sess"): msg = msg + "S... | def sendError(eng): assert self.SITE_MAIL, "must define SITE_MAIL first!" hr = "-" * 50 + "\n" msg = weblib.trim( """ To: %s From: weblib.cgi <%s> Subject: uncaught exception in %s |
expires= theCard.expMonth+"/"+theCard.expYear, | expires= str(theCard.expMonth)+"/"+\ str(theCard.expYear), | def act_checkout(self): """Records a sale in the database.""" |
if acct.result != payment.APPROVED: | if pmt.result != payment.APPROVED: | def act_checkout(self): """Records a sale in the database.""" |
content = self._submit(values, [("Referer", self.referer)]) | def authorize(self, amount): values = { | |
resdict = {} for item in content.split("<BR>")[:-1]: key, val = item.split("=", 1) resdict[key.lower()]=val | try: gotError = 0 content = self._submit(values, headers=[("Referer", self.referer)]) except: gotError = 1 | def authorize(self, amount): values = { |
if resdict["ioc_response_code"]=="0": self.result = payment.APPROVED self.error = None elif resdict.has_key("ioc_invalid_fields"): | if gotError: | def authorize(self, amount): values = { |
self.error = resdict["ioc_reject_description"] | self.error = "error connecting to merchant account" | def authorize(self, amount): values = { |
self.result = payment.DENIED self.error = resdict["ioc_reject_description"] | resdict = self._parse(content) | def authorize(self, amount): values = { |
self.store(item, _others={column:obj.ID}) | if item.private.isDirty: self.store(item, _others={column:obj.ID}) | def store(self, obj, _others={}): d = self._object_attrs_as_dict(obj) d.update(_others) klass = obj.__class__ tablename = self._unmap_class(klass) |
msg += self.eng.error | msg += str(self.eng.error) | def sendError(self): SITE_MAIL = self.eng.globals["SITE_MAIL"] SITE_NAME = self.eng.globals["SITE_NAME"] assert SITE_MAIL is not None, "must define SITE_MAIL first!" hr = "-" * 50 + "\n" msg = trim( """ To: %s From: cgi <%s> Subject: uncaught exception in %s |
handy.sendmail(msg) | sendmail(msg) | def sendError(self): SITE_MAIL = self.eng.globals["SITE_MAIL"] SITE_NAME = self.eng.globals["SITE_NAME"] assert SITE_MAIL is not None, "must define SITE_MAIL first!" hr = "-" * 50 + "\n" msg = trim( """ To: %s From: cgi <%s> Subject: uncaught exception in %s |
def build_gradient(): | def makeGradient(): | def build_gradient(): """ Returns a 160*10 Surface showing green-yellow-red gradient. """ colors = [] for i in range(0, 0xff, 0x22): colors.append((i, 0xff, 0)) colors.append((0xff, 0xff, 0)) for i in range(0xcc, -1, -0x22): colors.append((0xff, i, 0)) sprite = pygame.Surface((160, 10)) for x in range(len(colors)): py... |
def init(winsize): | def makeWindow(winsize): | def build_gradient(): """ Returns a 160*10 Surface showing green-yellow-red gradient. """ colors = [] for i in range(0, 0xff, 0x22): colors.append((i, 0xff, 0)) colors.append((0xff, 0xff, 0)) for i in range(0xcc, -1, -0x22): colors.append((0xff, i, 0)) sprite = pygame.Surface((160, 10)) for x in range(len(colors)): py... |
screen = init(winsize=(200, 400)) grad = build_gradient() | screen = makeWindow(winsize=(200, 400)) grad = makeGradient() | def main(): #@TODO: un-hardcode all these numbers screen = init(winsize=(200, 400)) grad = build_gradient() black = pygame.Surface((160,10)) black.fill((0,0,0)) done = 0 while not done: data = RandomArray.randint(0, 16, (32,)) for i in range(32): # draw the gradient, then cover part of it up: screen.blit(grad, (20, ... |
done = 0 while not done: | session = fakeSession() t = 0 | def main(): #@TODO: un-hardcode all these numbers screen = init(winsize=(200, 400)) grad = build_gradient() black = pygame.Surface((160,10)) black.fill((0,0,0)) done = 0 while not done: data = RandomArray.randint(0, 16, (32,)) for i in range(32): # draw the gradient, then cover part of it up: screen.blit(grad, (20, ... |
data = RandomArray.randint(0, 16, (32,)) | while keepLooping(): time.sleep(0.25) data = makeSpectrogram(session[t:t+64]) print data t += 64 if t >= len(session): t = 0 | def main(): #@TODO: un-hardcode all these numbers screen = init(winsize=(200, 400)) grad = build_gradient() black = pygame.Surface((160,10)) black.fill((0,0,0)) done = 0 while not done: data = RandomArray.randint(0, 16, (32,)) for i in range(32): # draw the gradient, then cover part of it up: screen.blit(grad, (20, ... |
pygame.display.update() for e in pygame.event.get(): if (e.type == KEYUP and e.key == K_ESCAPE) \ or (e.type == QUIT): done = 1 | def main(): #@TODO: un-hardcode all these numbers screen = init(winsize=(200, 400)) grad = build_gradient() black = pygame.Surface((160,10)) black.fill((0,0,0)) done = 0 while not done: data = RandomArray.randint(0, 16, (32,)) for i in range(32): # draw the gradient, then cover part of it up: screen.blit(grad, (20, ... | |
import pdb; pdb.set_trace() | def render(self, request): import pdb; pdb.set_trace() return self._thread(request) #d = threads.deferToThread(self._thread, request) #d.addCallback(self._finish, request) #return NOT_DONE_YET | |
frac = str(f)[:-1] | frac = str(f) if frac[-1]=="L": frac = frac[:-1] | def __str__(self): n, p = self.n, self.p i, f = divmod(abs(n), _tento(p)) if p: frac = str(f)[:-1] frac = "0" * (p - len(frac)) + frac else: frac = "" return "-"[:n<0] + \ str(i)[:-1] + \ "." + frac |
return "-"[:n<0] + \ str(i)[:-1] + \ "." + frac | str_i = str(i) if str_i =="L": str_i =str_i[:-1] return "-"[:n<0] + str_i + "." + frac | def __str__(self): n, p = self.n, self.p i, f = divmod(abs(n), _tento(p)) if p: frac = str(f)[:-1] frac = "0" * (p - len(frac)) + frac else: frac = "" return "-"[:n<0] + \ str(i)[:-1] + \ "." + frac |
def calcSalesTax(addressID): | def calcSalesTax(addressID, subtotal): | def calcSalesTax(addressID): import zikeshop #@TODO: put this somewhere else.. probably in the Sale object? #@TODO: Sale should have a reference to a "Store" object, and #@TODO: "Store" should have a .hasNexus(state) for sales tax.. ## see if the store has nexus in the customer's state cur = zikeshop.dbc.cursor() cur... |
return self.cart.subtotal() * \ | return subtotal * \ | def calcSalesTax(addressID): import zikeshop #@TODO: put this somewhere else.. probably in the Sale object? #@TODO: Sale should have a reference to a "Store" object, and #@TODO: "Store" should have a .hasNexus(state) for sales tax.. ## see if the store has nexus in the customer's state cur = zikeshop.dbc.cursor() cur... |
self.salestax = calcSalesTax(self.billAddressID) | self.salestax = calcSalesTax(self.billAddressID, self.cart.subtotal()) | def act_update(self): """ Update Cashier with some new information. This method allows you to inform the Cashier incrementally, if you want. Just post to the page with an 'update' action, and it'll recognize any of the required fields. """ for item in self.steps: if self.input.has_key(item): setattr(self, item, self.i... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.