desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Initialize a Babyl mailbox.'
def __init__(self, path, factory=None, create=True):
_singlefileMailbox.__init__(self, path, factory, create) self._labels = {}
'Add message and return assigned key.'
def add(self, message):
key = _singlefileMailbox.add(self, message) if isinstance(message, BabylMessage): self._labels[key] = message.get_labels() return key
'Remove the keyed message; raise KeyError if it doesn\'t exist.'
def remove(self, key):
_singlefileMailbox.remove(self, key) if (key in self._labels): del self._labels[key]
'Replace the keyed message; raise KeyError if it doesn\'t exist.'
def __setitem__(self, key, message):
_singlefileMailbox.__setitem__(self, key, message) if isinstance(message, BabylMessage): self._labels[key] = message.get_labels()
'Return a Message representation or raise a KeyError.'
def get_message(self, key):
(start, stop) = self._lookup(key) self._file.seek(start) self._file.readline() original_headers = StringIO.StringIO() while True: line = self._file.readline() if ((line == ('*** EOOH ***' + os.linesep)) or (line == '')): break original_headers.write(line.rep...
'Return a string representation or raise a KeyError.'
def get_string(self, key):
(start, stop) = self._lookup(key) self._file.seek(start) self._file.readline() original_headers = StringIO.StringIO() while True: line = self._file.readline() if ((line == ('*** EOOH ***' + os.linesep)) or (line == '')): break original_headers.write(line.rep...
'Return a file-like representation or raise a KeyError.'
def get_file(self, key):
return StringIO.StringIO(self.get_string(key).replace('\n', os.linesep))
'Return a list of user-defined labels in the mailbox.'
def get_labels(self):
self._lookup() labels = set() for label_list in self._labels.values(): labels.update(label_list) labels.difference_update(self._special_labels) return list(labels)
'Generate key-to-(start, stop) table of contents.'
def _generate_toc(self):
(starts, stops) = ([], []) self._file.seek(0) next_pos = 0 label_lists = [] while True: line_pos = next_pos line = self._file.readline() next_pos = self._file.tell() if (line == ('\x1f\x0c' + os.linesep)): if (len(stops) < len(starts)): sto...
'Called before writing the mailbox to file f.'
def _pre_mailbox_hook(self, f):
f.write(('BABYL OPTIONS:%sVersion: 5%sLabels:%s%s\x1f' % (os.linesep, os.linesep, ','.join(self.get_labels()), os.linesep)))
'Called before writing each message to file f.'
def _pre_message_hook(self, f):
f.write(('\x0c' + os.linesep))
'Called after writing each message to file f.'
def _post_message_hook(self, f):
f.write((os.linesep + '\x1f'))
'Write message contents and return (start, stop).'
def _install_message(self, message):
start = self._file.tell() if isinstance(message, BabylMessage): special_labels = [] labels = [] for label in message.get_labels(): if (label in self._special_labels): special_labels.append(label) else: labels.append(label) s...
'Initialize a Message instance.'
def __init__(self, message=None):
if isinstance(message, email.message.Message): self._become_message(copy.deepcopy(message)) if isinstance(message, Message): message._explain_to(self) elif isinstance(message, str): self._become_message(email.message_from_string(message)) elif hasattr(message, 'read'): ...
'Assume the non-format-specific state of message.'
def _become_message(self, message):
for name in ('_headers', '_unixfrom', '_payload', '_charset', 'preamble', 'epilogue', 'defects', '_default_type'): self.__dict__[name] = message.__dict__[name]
'Copy format-specific state to message insofar as possible.'
def _explain_to(self, message):
if isinstance(message, Message): return raise TypeError('Cannot convert to specified type')
'Initialize a MaildirMessage instance.'
def __init__(self, message=None):
self._subdir = 'new' self._info = '' self._date = time.time() Message.__init__(self, message)
'Return \'new\' or \'cur\'.'
def get_subdir(self):
return self._subdir
'Set subdir to \'new\' or \'cur\'.'
def set_subdir(self, subdir):
if ((subdir == 'new') or (subdir == 'cur')): self._subdir = subdir else: raise ValueError(("subdir must be 'new' or 'cur': %s" % subdir))
'Return as a string the flags that are set.'
def get_flags(self):
if self._info.startswith('2,'): return self._info[2:] else: return ''
'Set the given flags and unset all others.'
def set_flags(self, flags):
self._info = ('2,' + ''.join(sorted(flags)))
'Set the given flag(s) without changing others.'
def add_flag(self, flag):
self.set_flags(''.join((set(self.get_flags()) | set(flag))))
'Unset the given string flag(s) without changing others.'
def remove_flag(self, flag):
if (self.get_flags() != ''): self.set_flags(''.join((set(self.get_flags()) - set(flag))))
'Return delivery date of message, in seconds since the epoch.'
def get_date(self):
return self._date
'Set delivery date of message, in seconds since the epoch.'
def set_date(self, date):
try: self._date = float(date) except ValueError: raise TypeError(("can't convert to float: %s" % date))
'Get the message\'s "info" as a string.'
def get_info(self):
return self._info
'Set the message\'s "info" string.'
def set_info(self, info):
if isinstance(info, str): self._info = info else: raise TypeError(('info must be a string: %s' % type(info)))
'Copy Maildir-specific state to message insofar as possible.'
def _explain_to(self, message):
if isinstance(message, MaildirMessage): message.set_flags(self.get_flags()) message.set_subdir(self.get_subdir()) message.set_date(self.get_date()) elif isinstance(message, _mboxMMDFMessage): flags = set(self.get_flags()) if ('S' in flags): message.add_flag('R...
'Initialize an mboxMMDFMessage instance.'
def __init__(self, message=None):
self.set_from('MAILER-DAEMON', True) if isinstance(message, email.message.Message): unixfrom = message.get_unixfrom() if ((unixfrom is not None) and unixfrom.startswith('From ')): self.set_from(unixfrom[5:]) Message.__init__(self, message) return
'Return contents of "From " line.'
def get_from(self):
return self._from
'Set "From " line, formatting and appending time_ if specified.'
def set_from(self, from_, time_=None):
if (time_ is not None): if (time_ is True): time_ = time.gmtime() from_ += (' ' + time.asctime(time_)) self._from = from_ return
'Return as a string the flags that are set.'
def get_flags(self):
return (self.get('Status', '') + self.get('X-Status', ''))
'Set the given flags and unset all others.'
def set_flags(self, flags):
flags = set(flags) (status_flags, xstatus_flags) = ('', '') for flag in ('R', 'O'): if (flag in flags): status_flags += flag flags.remove(flag) for flag in ('D', 'F', 'A'): if (flag in flags): xstatus_flags += flag flags.remove(flag) xs...
'Set the given flag(s) without changing others.'
def add_flag(self, flag):
self.set_flags(''.join((set(self.get_flags()) | set(flag))))
'Unset the given string flag(s) without changing others.'
def remove_flag(self, flag):
if (('Status' in self) or ('X-Status' in self)): self.set_flags(''.join((set(self.get_flags()) - set(flag))))
'Copy mbox- or MMDF-specific state to message insofar as possible.'
def _explain_to(self, message):
if isinstance(message, MaildirMessage): flags = set(self.get_flags()) if ('O' in flags): message.set_subdir('cur') if ('F' in flags): message.add_flag('F') if ('A' in flags): message.add_flag('R') if ('R' in flags): message.add_...
'Initialize an MHMessage instance.'
def __init__(self, message=None):
self._sequences = [] Message.__init__(self, message)
'Return a list of sequences that include the message.'
def get_sequences(self):
return self._sequences[:]
'Set the list of sequences that include the message.'
def set_sequences(self, sequences):
self._sequences = list(sequences)
'Add sequence to list of sequences including the message.'
def add_sequence(self, sequence):
if isinstance(sequence, str): if (sequence not in self._sequences): self._sequences.append(sequence) else: raise TypeError(('sequence must be a string: %s' % type(sequence)))
'Remove sequence from the list of sequences including the message.'
def remove_sequence(self, sequence):
try: self._sequences.remove(sequence) except ValueError: pass
'Copy MH-specific state to message insofar as possible.'
def _explain_to(self, message):
if isinstance(message, MaildirMessage): sequences = set(self.get_sequences()) if ('unseen' in sequences): message.set_subdir('cur') else: message.set_subdir('cur') message.add_flag('S') if ('flagged' in sequences): message.add_flag('F')...
'Initialize an BabylMessage instance.'
def __init__(self, message=None):
self._labels = [] self._visible = Message() Message.__init__(self, message)
'Return a list of labels on the message.'
def get_labels(self):
return self._labels[:]
'Set the list of labels on the message.'
def set_labels(self, labels):
self._labels = list(labels)
'Add label to list of labels on the message.'
def add_label(self, label):
if isinstance(label, str): if (label not in self._labels): self._labels.append(label) else: raise TypeError(('label must be a string: %s' % type(label)))
'Remove label from the list of labels on the message.'
def remove_label(self, label):
try: self._labels.remove(label) except ValueError: pass
'Return a Message representation of visible headers.'
def get_visible(self):
return Message(self._visible)
'Set the Message representation of visible headers.'
def set_visible(self, visible):
self._visible = Message(visible)
'Update and/or sensibly generate a set of visible headers.'
def update_visible(self):
for header in self._visible.keys(): if (header in self): self._visible.replace_header(header, self[header]) else: del self._visible[header] for header in ('Date', 'From', 'Reply-To', 'To', 'CC', 'Subject'): if ((header in self) and (header not in self._visible)): ...
'Copy Babyl-specific state to message insofar as possible.'
def _explain_to(self, message):
if isinstance(message, MaildirMessage): labels = set(self.get_labels()) if ('unseen' in labels): message.set_subdir('cur') else: message.set_subdir('cur') message.add_flag('S') if (('forwarded' in labels) or ('resent' in labels)): messa...
'Initialize a _ProxyFile.'
def __init__(self, f, pos=None):
self._file = f if (pos is None): self._pos = f.tell() else: self._pos = pos return
'Read bytes.'
def read(self, size=None):
return self._read(size, self._file.read)
'Read a line.'
def readline(self, size=None):
return self._read(size, self._file.readline)
'Read multiple lines.'
def readlines(self, sizehint=None):
result = [] for line in self: result.append(line) if (sizehint is not None): sizehint -= len(line) if (sizehint <= 0): break return result
'Iterate over lines.'
def __iter__(self):
return iter(self.readline, '')
'Return the position.'
def tell(self):
return self._pos
'Change position.'
def seek(self, offset, whence=0):
if (whence == 1): self._file.seek(self._pos) self._file.seek(offset, whence) self._pos = self._file.tell()
'Close the file.'
def close(self):
del self._file
'Read size bytes using read_method.'
def _read(self, size, read_method):
if (size is None): size = (-1) self._file.seek(self._pos) result = read_method(size) self._pos = self._file.tell() return result
'Initialize a _PartialFile.'
def __init__(self, f, start=None, stop=None):
_ProxyFile.__init__(self, f, start) self._start = start self._stop = stop
'Return the position with respect to start.'
def tell(self):
return (_ProxyFile.tell(self) - self._start)
'Change position, possibly with respect to start or stop.'
def seek(self, offset, whence=0):
if (whence == 0): self._pos = self._start whence = 1 elif (whence == 2): self._pos = self._stop whence = 1 _ProxyFile.seek(self, offset, whence)
'Read size bytes using read_method, honoring start and stop.'
def _read(self, size, read_method):
remaining = (self._stop - self._pos) if (remaining <= 0): return '' else: if ((size is None) or (size < 0) or (size > remaining)): size = remaining return _ProxyFile._read(self, size, read_method)
'Run the module after setting up the environment. First check the syntax. If OK, make sure the shell is active and then transfer the arguments, set the run environment\'s working directory to the directory of the module being executed and also add that directory to its sys.path if not already included.'
def run_module_event(self, event):
filename = self.getfilename() if (not filename): return 'break' code = self.checksyntax(filename) if (not code): return 'break' if (not self.tabnanny(filename)): return 'break' shell = self.shell interp = shell.interp if PyShell.use_subprocess: shell.resta...
'Get source filename. If not saved, offer to save (or create) file The debugger requires a source file. Make sure there is one, and that the current version of the source buffer has been saved. If the user declines to save or cancels the Save As dialog, return None. If the user has configured IDLE for Autosave, the ...
def getfilename(self):
filename = self.editwin.io.filename if (not self.editwin.get_saved()): autosave = idleConf.GetOption('main', 'General', 'autosave', type='bool') if (autosave and filename): self.editwin.io.save(None) else: confirm = self.ask_save_dialog() self.editwin....
'Load PyShellEditorWindow breakpoints into subprocess debugger'
def load_breakpoints(self):
pyshell_edit_windows = self.pyshell.flist.inversedict.keys() for editwin in pyshell_edit_windows: filename = editwin.io.filename try: for lineno in editwin.breakpoints: self.set_breakpoint_here(filename, lineno) except AttributeError: continue
'override base method'
def popup_event(self, event):
if self.stack: return ScrolledList.popup_event(self, event)
'override base method'
def fill_menu(self):
menu = self.menu menu.add_command(label='Go to source line', command=self.goto_source_line) menu.add_command(label='Show stack frame', command=self.show_stack_frame)
'override base method'
def on_select(self, index):
if (0 <= index < len(self.stack)): self.gui.show_frame(self.stack[index])
'override base method'
def on_double(self, index):
self.show_source(index)
'Create a Unicode string If that fails, let Tcl try its best'
def decode(self, chars):
if chars.startswith(BOM_UTF8): try: chars = chars[3:].decode('utf-8') except UnicodeError: return chars self.fileencoding = BOM_UTF8 return chars try: enc = coding_spec(chars) except LookupError as name: tkMessageBox.showerror(title='Er...
'Update recent file list on all editor windows'
def updaterecentfileslist(self, filename):
self.editwin.update_recent_files_list(filename)
'Constructor arguments: select_command -- A callable which will be called when a tab is selected. It is called with the name of the selected tab as an argument. tabs -- A list of strings, the names of the tabs. Should be specified in the desired tab order. The first tab will be the default and first active tab. If tabs...
def __init__(self, page_set, select_command, tabs=None, n_rows=1, max_tabs_per_row=5, expand_tabs=False, **kw):
Frame.__init__(self, page_set, **kw) self.select_command = select_command self.n_rows = n_rows self.max_tabs_per_row = max_tabs_per_row self.expand_tabs = expand_tabs self.page_set = page_set self._tabs = {} self._tab2row = {} if tabs: self._tab_names = list(tabs) else: ...
'Add a new tab with the name given in tab_name.'
def add_tab(self, tab_name):
if (not tab_name): raise InvalidNameError(("Invalid Tab name: '%s'" % tab_name)) if (tab_name in self._tab_names): raise AlreadyExistsError(("Tab named '%s' already exists" % tab_name)) self._tab_names.append(tab_name) self._arrange_tabs()
'Remove the tab named <tab_name>'
def remove_tab(self, tab_name):
if (tab_name not in self._tab_names): raise KeyError(("No such Tab: '%s" % page_name)) self._tab_names.remove(tab_name) self._arrange_tabs()
'Show the tab named <tab_name> as the selected one'
def set_selected_tab(self, tab_name):
if (tab_name == self._selected_tab): return else: if ((tab_name is not None) and (tab_name not in self._tabs)): raise KeyError(("No such Tab: '%s" % page_name)) if (self._selected_tab is not None): self._tabs[self._selected_tab].set_normal() self....
'Arrange the tabs in rows, in the order in which they were added. If n_rows >= 1, this will be the number of rows used. Otherwise the number of rows will be calculated according to the number of tabs and max_tabs_per_row. In this case, the number of rows may change when adding/removing tabs.'
def _arrange_tabs(self):
for tab_name in self._tabs.keys(): self._tabs.pop(tab_name).destroy() self._reset_tab_rows() if (not self._tab_names): return else: if ((self.n_rows is not None) and (self.n_rows > 0)): n_rows = self.n_rows else: n_rows = (((len(self._tab_names) - ...
'Constructor arguments: name -- The tab\'s name, which will appear in its button. select_command -- The command to be called upon selection of the tab. It is called with the tab\'s name as an argument.'
def __init__(self, name, select_command, tab_row, tab_set):
Frame.__init__(self, tab_row, borderwidth=self.bw, relief=RAISED) self.name = name self.select_command = select_command self.tab_set = tab_set self.is_last_in_row = False self.button = Radiobutton(self, text=name, command=self._select_event, padx=5, pady=1, takefocus=FALSE, indicatoron=FALSE, hi...
'Event handler for tab selection. With TabbedPageSet, this calls TabbedPageSet.change_page, so that selecting a tab changes the page. Note that this does -not- call set_selected -- it will be called by TabSet.set_selected_tab, which should be called when whatever the tabs are related to changes.'
def _select_event(self, *args):
self.select_command(self.name)
'Assume selected look'
def set_selected(self):
self._place_masks(selected=True)
'Assume normal look'
def set_normal(self):
self._place_masks(selected=False)
'Constructor arguments: page_names -- A list of strings, each will be the dictionary key to a page\'s widget, and the name displayed on the page\'s tab. Should be specified in the desired page order. The first page will be the default and first active page. If page_names is None or empty, the TabbedPageSet will be init...
def __init__(self, parent, page_names=None, page_class=PageLift, n_rows=1, max_tabs_per_row=5, expand_tabs=False, **kw):
Frame.__init__(self, parent, **kw) self.page_class = page_class self.pages = {} self._pages_order = [] self._current_page = None self._default_page = None self.columnconfigure(0, weight=1) self.rowconfigure(1, weight=1) self.pages_frame = Frame(self) self.pages_frame.grid(row=1, ...
'Add a new page with the name given in page_name.'
def add_page(self, page_name):
if (not page_name): raise InvalidNameError(("Invalid TabPage name: '%s'" % page_name)) if (page_name in self.pages): raise AlreadyExistsError(("TabPage named '%s' already exists" % page_name)) self.pages[page_name] = self.page_class(self.pages_frame) self._pages_orde...
'Destroy the page whose name is given in page_name.'
def remove_page(self, page_name):
if (page_name not in self.pages): raise KeyError(("No such TabPage: '%s" % page_name)) self._pages_order.remove(page_name) if (len(self._pages_order) > 0): if (page_name == self._default_page): self._default_page = self._pages_order[0] else: self._default_pag...
'Show the page whose name is given in page_name.'
def change_page(self, page_name):
if (self._current_page == page_name): return else: if ((page_name is not None) and (page_name not in self.pages)): raise KeyError(("No such TabPage: '%s'" % page_name)) if (self._current_page is not None): self.pages[self._current_page]._hide() se...
'cfgFile - string, fully specified configuration file name'
def __init__(self, cfgFile, cfgDefaults=None):
self.file = cfgFile ConfigParser.__init__(self, defaults=cfgDefaults)
'Get an option value for given section/option or return default. If type is specified, return as type.'
def Get(self, section, option, type=None, default=None, raw=False):
if (not self.has_option(section, option)): return default else: if (type == 'bool'): return self.getboolean(section, option) if (type == 'int'): return self.getint(section, option) return self.get(section, option, raw=raw)
'Get an option list for given section'
def GetOptionList(self, section):
if self.has_section(section): return self.options(section) else: return []
'Load the configuration file from disk'
def Load(self):
self.read(self.file)
'if section doesn\'t exist, add it'
def AddSection(self, section):
if (not self.has_section(section)): self.add_section(section)
'remove any sections that have no options'
def RemoveEmptySections(self):
for section in self.sections(): if (not self.GetOptionList(section)): self.remove_section(section)
'Remove empty sections and then return 1 if parser has no sections left, else return 0.'
def IsEmpty(self):
self.RemoveEmptySections() if self.sections(): return 0 else: return 1
'If section/option exists, remove it. Returns 1 if option was removed, 0 otherwise.'
def RemoveOption(self, section, option):
if self.has_section(section): return self.remove_option(section, option)
'Sets option to value, adding section if required. Returns 1 if option was added or changed, otherwise 0.'
def SetOption(self, section, option, value):
if self.has_option(section, option): if (self.get(section, option) == value): return 0 else: self.set(section, option, value) return 1 else: if (not self.has_section(section)): self.add_section(section) self.set(section, option, val...
'Removes the user config file from disk if it exists.'
def RemoveFile(self):
if os.path.exists(self.file): os.remove(self.file)
'Update user configuration file. Remove empty sections. If resulting config isn\'t empty, write the file to disk. If config is empty, remove the file from disk if it exists.'
def Save(self):
if (not self.IsEmpty()): fname = self.file try: cfgFile = open(fname, 'w') except IOError: os.unlink(fname) cfgFile = open(fname, 'w') self.write(cfgFile) else: self.RemoveFile()
'set up a dictionary of config parsers for default and user configurations respectively'
def CreateConfigHandlers(self):
if (__name__ != '__main__'): idleDir = os.path.dirname(__file__) else: idleDir = os.path.abspath(sys.path[0]) userDir = self.GetUserCfgDir() configTypes = ('main', 'extensions', 'highlight', 'keys') defCfgFiles = {} usrCfgFiles = {} for cfgType in configTypes: defCfgF...
'Creates (if required) and returns a filesystem directory for storing user config files.'
def GetUserCfgDir(self):
cfgDir = '.idlerc' userDir = os.path.expanduser('~') if (userDir != '~'): if (not os.path.exists(userDir)): warn = (('\n Warning: os.path.expanduser("~") points to\n ' + userDir) + ',\n but the path does not exist.\n') try: sys...
'Get an option value for given config type and given general configuration section/option or return a default. If type is specified, return as type. Firstly the user configuration is checked, with a fallback to the default configuration, and a final \'catch all\' fallback to a useable passed-in default if the option is...
def GetOption(self, configType, section, option, default=None, type=None, warn_on_default=True, raw=False):
if self.userCfg[configType].has_option(section, option): return self.userCfg[configType].Get(section, option, type=type, raw=raw) else: if self.defaultCfg[configType].has_option(section, option): return self.defaultCfg[configType].Get(section, option, type=type, raw=raw) if w...