code
stringlengths
26
870k
docstring
stringlengths
1
65.6k
func_name
stringlengths
1
194
language
stringclasses
1 value
repo
stringlengths
8
68
path
stringlengths
5
194
url
stringlengths
46
254
license
stringclasses
4 values
def is_all_white(line): """Return True if line is empty or all whitespace.""" return re.match(r"^\s*$", line) is not None
Return True if line is empty or all whitespace.
is_all_white
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/format.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/format.py
MIT
def get_indent(line): """Return the initial space or tab indent of line.""" return re.match(r"^([ \t]*)", line).group()
Return the initial space or tab indent of line.
get_indent
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/format.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/format.py
MIT
def get_comment_header(line): """Return string with leading whitespace and '#' from line or ''. A null return indicates that the line is not a comment line. A non- null return, such as ' #', will be used to find the other lines of a comment block with the same indent. """ m = re.match(r"^([ \t]*#*)", line) if m is None: return "" return m.group(1)
Return string with leading whitespace and '#' from line or ''. A null return indicates that the line is not a comment line. A non- null return, such as ' #', will be used to find the other lines of a comment block with the same indent.
get_comment_header
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/format.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/format.py
MIT
def get_line_indent(line, tabwidth): """Return a line's indentation as (# chars, effective # of spaces). The effective # of spaces is the length after properly "expanding" the tabs into spaces, as done by str.expandtabs(tabwidth). """ m = _line_indent_re.match(line) return m.end(), len(m.group().expandtabs(tabwidth))
Return a line's indentation as (# chars, effective # of spaces). The effective # of spaces is the length after properly "expanding" the tabs into spaces, as done by str.expandtabs(tabwidth).
get_line_indent
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/format.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/format.py
MIT
def get_region(self): """Return line information about the selected text region. If text is selected, the first and last indices will be for the selection. If there is no text selected, the indices will be the current cursor location. Return a tuple containing (first index, last index, string representation of text, list of text lines). """ text = self.editwin.text first, last = self.editwin.get_selection_indices() if first and last: head = text.index(first + " linestart") tail = text.index(last + "-1c lineend +1c") else: head = text.index("insert linestart") tail = text.index("insert lineend +1c") chars = text.get(head, tail) lines = chars.split("\n") return head, tail, chars, lines
Return line information about the selected text region. If text is selected, the first and last indices will be for the selection. If there is no text selected, the indices will be the current cursor location. Return a tuple containing (first index, last index, string representation of text, list of text lines).
get_region
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/format.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/format.py
MIT
def set_region(self, head, tail, chars, lines): """Replace the text between the given indices. Args: head: Starting index of text to replace. tail: Ending index of text to replace. chars: Expected to be string of current text between head and tail. lines: List of new lines to insert between head and tail. """ text = self.editwin.text newchars = "\n".join(lines) if newchars == chars: text.bell() return text.tag_remove("sel", "1.0", "end") text.mark_set("insert", head) text.undo_block_start() text.delete(head, tail) text.insert(head, newchars) text.undo_block_stop() text.tag_add("sel", head, "insert")
Replace the text between the given indices. Args: head: Starting index of text to replace. tail: Ending index of text to replace. chars: Expected to be string of current text between head and tail. lines: List of new lines to insert between head and tail.
set_region
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/format.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/format.py
MIT
def comment_region_event(self, event=None): """Comment out each line in region. ## is appended to the beginning of each line to comment it out. """ head, tail, chars, lines = self.get_region() for pos in range(len(lines) - 1): line = lines[pos] lines[pos] = '##' + line self.set_region(head, tail, chars, lines) return "break"
Comment out each line in region. ## is appended to the beginning of each line to comment it out.
comment_region_event
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/format.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/format.py
MIT
def uncomment_region_event(self, event=None): """Uncomment each line in region. Remove ## or # in the first positions of a line. If the comment is not in the beginning position, this command will have no effect. """ head, tail, chars, lines = self.get_region() for pos in range(len(lines)): line = lines[pos] if not line: continue if line[:2] == '##': line = line[2:] elif line[:1] == '#': line = line[1:] lines[pos] = line self.set_region(head, tail, chars, lines) return "break"
Uncomment each line in region. Remove ## or # in the first positions of a line. If the comment is not in the beginning position, this command will have no effect.
uncomment_region_event
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/format.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/format.py
MIT
def file_line_helper(line): """Extract file name and line number from line of text. Check if line of text contains one of the file/line patterns. If it does and if the file and line are valid, return a tuple of the file name and line number. If it doesn't match or if the file or line is invalid, return None. """ if not file_line_progs: compile_progs() for prog in file_line_progs: match = prog.search(line) if match: filename, lineno = match.group(1, 2) try: f = open(filename, "r") f.close() break except OSError: continue else: return None try: return filename, int(lineno) except TypeError: return None
Extract file name and line number from line of text. Check if line of text contains one of the file/line patterns. If it does and if the file and line are valid, return a tuple of the file name and line number. If it doesn't match or if the file or line is invalid, return None.
file_line_helper
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/outwin.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/outwin.py
MIT
def write(self, s, tags=(), mark="insert"): """Write text to text widget. The text is inserted at the given index with the provided tags. The text widget is then scrolled to make it visible and updated to display it, giving the effect of seeing each line as it is added. Args: s: Text to insert into text widget. tags: Tuple of tag strings to apply on the insert. mark: Index for the insert. Return: Length of text inserted. """ if isinstance(s, bytes): s = s.decode(iomenu.encoding, "replace") self.text.insert(mark, s, tags) self.text.see(mark) self.text.update() return len(s)
Write text to text widget. The text is inserted at the given index with the provided tags. The text widget is then scrolled to make it visible and updated to display it, giving the effect of seeing each line as it is added. Args: s: Text to insert into text widget. tags: Tuple of tag strings to apply on the insert. mark: Index for the insert. Return: Length of text inserted.
write
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/outwin.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/outwin.py
MIT
def goto_file_line(self, event=None): """Handle request to open file/line. If the selected or previous line in the output window contains a file name and line number, then open that file name in a new window and position on the line number. Otherwise, display an error messagebox. """ line = self.text.get("insert linestart", "insert lineend") result = file_line_helper(line) if not result: # Try the previous line. This is handy e.g. in tracebacks, # where you tend to right-click on the displayed source line line = self.text.get("insert -1line linestart", "insert -1line lineend") result = file_line_helper(line) if not result: self.showerror( "No special line", "The line you point at doesn't look like " "a valid file name followed by a line number.", parent=self.text) return filename, lineno = result self.flist.gotofileline(filename, lineno)
Handle request to open file/line. If the selected or previous line in the output window contains a file name and line number, then open that file name in a new window and position on the line number. Otherwise, display an error messagebox.
goto_file_line
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/outwin.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/outwin.py
MIT
def idle_showwarning( message, category, filename, lineno, file=None, line=None): """Show Idle-format warning (after replacing warnings.showwarning). The differences are the formatter called, the file=None replacement, which can be None, the capture of the consequence AttributeError, and the output of a hard-coded prompt. """ if file is None: file = warning_stream try: file.write(idle_formatwarning( message, category, filename, lineno, line=line)) file.write(">>> ") except (AttributeError, OSError): pass # if file (probably __stderr__) is invalid, skip warning.
Show Idle-format warning (after replacing warnings.showwarning). The differences are the formatter called, the file=None replacement, which can be None, the capture of the consequence AttributeError, and the output of a hard-coded prompt.
idle_showwarning
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/pyshell.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/pyshell.py
MIT
def extended_linecache_checkcache(filename=None, orig_checkcache=linecache.checkcache): """Extend linecache.checkcache to preserve the <pyshell#...> entries Rather than repeating the linecache code, patch it to save the <pyshell#...> entries, call the original linecache.checkcache() (skipping them), and then restore the saved entries. orig_checkcache is bound at definition time to the original method, allowing it to be patched. """ cache = linecache.cache save = {} for key in list(cache): if key[:1] + key[-1:] == '<>': save[key] = cache.pop(key) orig_checkcache(filename) cache.update(save)
Extend linecache.checkcache to preserve the <pyshell#...> entries Rather than repeating the linecache code, patch it to save the <pyshell#...> entries, call the original linecache.checkcache() (skipping them), and then restore the saved entries. orig_checkcache is bound at definition time to the original method, allowing it to be patched.
extended_linecache_checkcache
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/pyshell.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/pyshell.py
MIT
def restart_line(width, filename): # See bpo-38141. """Return width long restart line formatted with filename. Fill line with balanced '='s, with any extras and at least one at the beginning. Do not end with a trailing space. """ tag = f"= RESTART: {filename or 'Shell'} =" if width >= len(tag): div, mod = divmod((width -len(tag)), 2) return f"{(div+mod)*'='}{tag}{div*'='}" else: return tag[:-2] # Remove ' ='.
Return width long restart line formatted with filename. Fill line with balanced '='s, with any extras and at least one at the beginning. Do not end with a trailing space.
restart_line
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/pyshell.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/pyshell.py
MIT
def open_remote_stack_viewer(self): """Initiate the remote stack viewer from a separate thread. This method is called from the subprocess, and by returning from this method we allow the subprocess to unblock. After a bit the shell requests the subprocess to open the remote stack viewer which returns a static object looking at the last exception. It is queried through the RPC mechanism. """ self.tkconsole.text.after(300, self.remote_stack_viewer) return
Initiate the remote stack viewer from a separate thread. This method is called from the subprocess, and by returning from this method we allow the subprocess to unblock. After a bit the shell requests the subprocess to open the remote stack viewer which returns a static object looking at the last exception. It is queried through the RPC mechanism.
open_remote_stack_viewer
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/pyshell.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/pyshell.py
MIT
def showsyntaxerror(self, filename=None): """Override Interactive Interpreter method: Use Colorizing Color the offending position instead of printing it and pointing at it with a caret. """ tkconsole = self.tkconsole text = tkconsole.text text.tag_remove("ERROR", "1.0", "end") type, value, tb = sys.exc_info() msg = getattr(value, 'msg', '') or value or "<no detail available>" lineno = getattr(value, 'lineno', '') or 1 offset = getattr(value, 'offset', '') or 0 if offset == 0: lineno += 1 #mark end of offending line if lineno == 1: pos = "iomark + %d chars" % (offset-1) else: pos = "iomark linestart + %d lines + %d chars" % \ (lineno-1, offset-1) tkconsole.colorize_syntax_error(text, pos) tkconsole.resetoutput() self.write("SyntaxError: %s\n" % msg) tkconsole.showprompt()
Override Interactive Interpreter method: Use Colorizing Color the offending position instead of printing it and pointing at it with a caret.
showsyntaxerror
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/pyshell.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/pyshell.py
MIT
def copy_strip(): """Copy idle.html to idlelib/help.html, stripping trailing whitespace. Files with trailing whitespace cannot be pushed to the git cpython repository. For 3.x (on Windows), help.html is generated, after editing idle.rst on the master branch, with sphinx-build -bhtml . build/html python_d.exe -c "from idlelib.help import copy_strip; copy_strip()" Check build/html/library/idle.html, the help.html diff, and the text displayed by Help => IDLE Help. Add a blurb and create a PR. It can be worthwhile to occasionally generate help.html without touching idle.rst. Changes to the master version and to the doc build system may result in changes that should not changed the displayed text, but might break HelpParser. As long as master and maintenance versions of idle.rst remain the same, help.html can be backported. The internal Python version number is not displayed. If maintenance idle.rst diverges from the master version, then instead of backporting help.html from master, repeat the procedure above to generate a maintenance version. """ src = join(abspath(dirname(dirname(dirname(__file__)))), 'Doc', 'build', 'html', 'library', 'idle.html') dst = join(abspath(dirname(__file__)), 'help.html') with open(src, 'rb') as inn,\ open(dst, 'wb') as out: for line in inn: out.write(line.rstrip() + b'\n') print(f'{src} copied to {dst}')
Copy idle.html to idlelib/help.html, stripping trailing whitespace. Files with trailing whitespace cannot be pushed to the git cpython repository. For 3.x (on Windows), help.html is generated, after editing idle.rst on the master branch, with sphinx-build -bhtml . build/html python_d.exe -c "from idlelib.help import copy_strip; copy_strip()" Check build/html/library/idle.html, the help.html diff, and the text displayed by Help => IDLE Help. Add a blurb and create a PR. It can be worthwhile to occasionally generate help.html without touching idle.rst. Changes to the master version and to the doc build system may result in changes that should not changed the displayed text, but might break HelpParser. As long as master and maintenance versions of idle.rst remain the same, help.html can be backported. The internal Python version number is not displayed. If maintenance idle.rst diverges from the master version, then instead of backporting help.html from master, repeat the procedure above to generate a maintenance version.
copy_strip
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/help.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/help.py
MIT
def __init__(self, parent, title=None, *, _htest=False, _utest=False): """Create popup, do not return until tk widget destroyed. parent - parent of this dialog title - string which is title of popup dialog _htest - bool, change box location when running htest _utest - bool, don't wait_window when running unittest """ Toplevel.__init__(self, parent) self.configure(borderwidth=5) # place dialog below parent if running htest self.geometry("+%d+%d" % ( parent.winfo_rootx()+30, parent.winfo_rooty()+(30 if not _htest else 100))) self.bg = "#bbbbbb" self.fg = "#000000" self.create_widgets() self.resizable(height=False, width=False) self.title(title or f'About IDLE {python_version()} ({build_bits()} bit)') self.transient(parent) self.grab_set() self.protocol("WM_DELETE_WINDOW", self.ok) self.parent = parent self.button_ok.focus_set() self.bind('<Return>', self.ok) # dismiss dialog self.bind('<Escape>', self.ok) # dismiss dialog self._current_textview = None self._utest = _utest if not _utest: self.deiconify() self.wait_window()
Create popup, do not return until tk widget destroyed. parent - parent of this dialog title - string which is title of popup dialog _htest - bool, change box location when running htest _utest - bool, don't wait_window when running unittest
__init__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/help_about.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/help_about.py
MIT
def display_printer_text(self, title, printer): """Create textview for built-in constants. Built-in constants have type _sitebuiltins._Printer. The text is extracted from the built-in and then sent to a text viewer with self as the parent and title as the title of the popup. """ printer._Printer__setup() text = '\n'.join(printer._Printer__lines) self._current_textview = textview.view_text( self, title, text, _utest=self._utest)
Create textview for built-in constants. Built-in constants have type _sitebuiltins._Printer. The text is extracted from the built-in and then sent to a text viewer with self as the parent and title as the title of the popup.
display_printer_text
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/help_about.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/help_about.py
MIT
def display_file_text(self, title, filename, encoding=None): """Create textview for filename. The filename needs to be in the current directory. The path is sent to a text viewer with self as the parent, title as the title of the popup, and the file encoding. """ fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename) self._current_textview = textview.view_file( self, title, fn, encoding, _utest=self._utest)
Create textview for filename. The filename needs to be in the current directory. The path is sent to a text viewer with self as the parent, title as the title of the popup, and the file encoding.
display_file_text
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/help_about.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/help_about.py
MIT
def count_lines_with_wrapping(s, linewidth=80): """Count the number of lines in a given string. Lines are counted as if the string was wrapped so that lines are never over linewidth characters long. Tabs are considered tabwidth characters long. """ tabwidth = 8 # Currently always true in Shell. pos = 0 linecount = 1 current_column = 0 for m in re.finditer(r"[\t\n]", s): # Process the normal chars up to tab or newline. numchars = m.start() - pos pos += numchars current_column += numchars # Deal with tab or newline. if s[pos] == '\n': # Avoid the `current_column == 0` edge-case, and while we're # at it, don't bother adding 0. if current_column > linewidth: # If the current column was exactly linewidth, divmod # would give (1,0), even though a new line hadn't yet # been started. The same is true if length is any exact # multiple of linewidth. Therefore, subtract 1 before # dividing a non-empty line. linecount += (current_column - 1) // linewidth linecount += 1 current_column = 0 else: assert s[pos] == '\t' current_column += tabwidth - (current_column % tabwidth) # If a tab passes the end of the line, consider the entire # tab as being on the next line. if current_column > linewidth: linecount += 1 current_column = tabwidth pos += 1 # After the tab or newline. # Process remaining chars (no more tabs or newlines). current_column += len(s) - pos # Avoid divmod(-1, linewidth). if current_column > 0: linecount += (current_column - 1) // linewidth else: # Text ended with newline; don't count an extra line after it. linecount -= 1 return linecount
Count the number of lines in a given string. Lines are counted as if the string was wrapped so that lines are never over linewidth characters long. Tabs are considered tabwidth characters long.
count_lines_with_wrapping
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/squeezer.py
MIT
def expand(self, event=None): """expand event handler This inserts the original text in place of the button in the Text widget, removes the button and updates the Squeezer instance. If the original text is dangerously long, i.e. expanding it could cause a performance degradation, ask the user for confirmation. """ if self.is_dangerous is None: self.set_is_dangerous() if self.is_dangerous: confirm = tkMessageBox.askokcancel( title="Expand huge output?", message="\n\n".join([ "The squeezed output is very long: %d lines, %d chars.", "Expanding it could make IDLE slow or unresponsive.", "It is recommended to view or copy the output instead.", "Really expand?" ]) % (self.numoflines, len(self.s)), default=tkMessageBox.CANCEL, parent=self.text) if not confirm: return "break" self.base_text.insert(self.text.index(self), self.s, self.tags) self.base_text.delete(self) self.squeezer.expandingbuttons.remove(self)
expand event handler This inserts the original text in place of the button in the Text widget, removes the button and updates the Squeezer instance. If the original text is dangerously long, i.e. expanding it could cause a performance degradation, ask the user for confirmation.
expand
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/squeezer.py
MIT
def copy(self, event=None): """copy event handler Copy the original text to the clipboard. """ self.clipboard_clear() self.clipboard_append(self.s)
copy event handler Copy the original text to the clipboard.
copy
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/squeezer.py
MIT
def view(self, event=None): """view event handler View the original text in a separate text viewer window. """ view_text(self.text, "Squeezed Output Viewer", self.s, modal=False, wrap='none')
view event handler View the original text in a separate text viewer window.
view
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/squeezer.py
MIT
def reload(cls): """Load class variables from config.""" cls.auto_squeeze_min_lines = idleConf.GetOption( "main", "PyShell", "auto-squeeze-min-lines", type="int", default=50, )
Load class variables from config.
reload
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/squeezer.py
MIT
def __init__(self, editwin): """Initialize settings for Squeezer. editwin is the shell's Editor window. self.text is the editor window text widget. self.base_test is the actual editor window Tk text widget, rather than EditorWindow's wrapper. self.expandingbuttons is the list of all buttons representing "squeezed" output. """ self.editwin = editwin self.text = text = editwin.text # Get the base Text widget of the PyShell object, used to change # text before the iomark. PyShell deliberately disables changing # text before the iomark via its 'text' attribute, which is # actually a wrapper for the actual Text widget. Squeezer, # however, needs to make such changes. self.base_text = editwin.per.bottom # Twice the text widget's border width and internal padding; # pre-calculated here for the get_line_width() method. self.window_width_delta = 2 * ( int(text.cget('border')) + int(text.cget('padx')) ) self.expandingbuttons = [] # Replace the PyShell instance's write method with a wrapper, # which inserts an ExpandingButton instead of a long text. def mywrite(s, tags=(), write=editwin.write): # Only auto-squeeze text which has just the "stdout" tag. if tags != "stdout": return write(s, tags) # Only auto-squeeze text with at least the minimum # configured number of lines. auto_squeeze_min_lines = self.auto_squeeze_min_lines # First, a very quick check to skip very short texts. if len(s) < auto_squeeze_min_lines: return write(s, tags) # Now the full line-count check. numoflines = self.count_lines(s) if numoflines < auto_squeeze_min_lines: return write(s, tags) # Create an ExpandingButton instance. expandingbutton = ExpandingButton(s, tags, numoflines, self) # Insert the ExpandingButton into the Text widget. text.mark_gravity("iomark", tk.RIGHT) text.window_create("iomark", window=expandingbutton, padx=3, pady=5) text.see("iomark") text.update() text.mark_gravity("iomark", tk.LEFT) # Add the ExpandingButton to the Squeezer's list. self.expandingbuttons.append(expandingbutton) editwin.write = mywrite
Initialize settings for Squeezer. editwin is the shell's Editor window. self.text is the editor window text widget. self.base_test is the actual editor window Tk text widget, rather than EditorWindow's wrapper. self.expandingbuttons is the list of all buttons representing "squeezed" output.
__init__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/squeezer.py
MIT
def count_lines(self, s): """Count the number of lines in a given text. Before calculation, the tab width and line length of the text are fetched, so that up-to-date values are used. Lines are counted as if the string was wrapped so that lines are never over linewidth characters long. Tabs are considered tabwidth characters long. """ return count_lines_with_wrapping(s, self.editwin.width)
Count the number of lines in a given text. Before calculation, the tab width and line length of the text are fetched, so that up-to-date values are used. Lines are counted as if the string was wrapped so that lines are never over linewidth characters long. Tabs are considered tabwidth characters long.
count_lines
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/squeezer.py
MIT
def squeeze_current_text_event(self, event): """squeeze-current-text event handler Squeeze the block of text inside which contains the "insert" cursor. If the insert cursor is not in a squeezable block of text, give the user a small warning and do nothing. """ # Set tag_name to the first valid tag found on the "insert" cursor. tag_names = self.text.tag_names(tk.INSERT) for tag_name in ("stdout", "stderr"): if tag_name in tag_names: break else: # The insert cursor doesn't have a "stdout" or "stderr" tag. self.text.bell() return "break" # Find the range to squeeze. start, end = self.text.tag_prevrange(tag_name, tk.INSERT + "+1c") s = self.text.get(start, end) # If the last char is a newline, remove it from the range. if len(s) > 0 and s[-1] == '\n': end = self.text.index("%s-1c" % end) s = s[:-1] # Delete the text. self.base_text.delete(start, end) # Prepare an ExpandingButton. numoflines = self.count_lines(s) expandingbutton = ExpandingButton(s, tag_name, numoflines, self) # insert the ExpandingButton to the Text self.text.window_create(start, window=expandingbutton, padx=3, pady=5) # Insert the ExpandingButton to the list of ExpandingButtons, # while keeping the list ordered according to the position of # the buttons in the Text widget. i = len(self.expandingbuttons) while i > 0 and self.text.compare(self.expandingbuttons[i-1], ">", expandingbutton): i -= 1 self.expandingbuttons.insert(i, expandingbutton) return "break"
squeeze-current-text event handler Squeeze the block of text inside which contains the "insert" cursor. If the insert cursor is not in a squeezable block of text, give the user a small warning and do nothing.
squeeze_current_text_event
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/squeezer.py
MIT
def __init__(self, parent, title='', *, _htest=False, _utest=False): """Show the tabbed dialog for user configuration. Args: parent - parent of this dialog title - string which is the title of this popup dialog _htest - bool, change box location when running htest _utest - bool, don't wait_window when running unittest Note: Focus set on font page fontlist. Methods: create_widgets cancel: Bound to DELETE_WINDOW protocol. """ Toplevel.__init__(self, parent) self.parent = parent if _htest: parent.instance_dict = {} if not _utest: self.withdraw() self.configure(borderwidth=5) self.title(title or 'IDLE Preferences') x = parent.winfo_rootx() + 20 y = parent.winfo_rooty() + (30 if not _htest else 150) self.geometry(f'+{x}+{y}') # Each theme element key is its display name. # The first value of the tuple is the sample area tag name. # The second value is the display name list sort index. self.create_widgets() self.resizable(height=FALSE, width=FALSE) self.transient(parent) self.protocol("WM_DELETE_WINDOW", self.cancel) self.fontpage.fontlist.focus_set() # XXX Decide whether to keep or delete these key bindings. # Key bindings for this dialog. # self.bind('<Escape>', self.Cancel) #dismiss dialog, no save # self.bind('<Alt-a>', self.Apply) #apply changes, save # self.bind('<F1>', self.Help) #context help # Attach callbacks after loading config to avoid calling them. tracers.attach() if not _utest: self.grab_set() self.wm_deiconify() self.wait_window()
Show the tabbed dialog for user configuration. Args: parent - parent of this dialog title - string which is the title of this popup dialog _htest - bool, change box location when running htest _utest - bool, don't wait_window when running unittest Note: Focus set on font page fontlist. Methods: create_widgets cancel: Bound to DELETE_WINDOW protocol.
__init__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def create_widgets(self): """Create and place widgets for tabbed dialog. Widgets Bound to self: note: Notebook highpage: HighPage fontpage: FontPage keyspage: KeysPage genpage: GenPage extpage: self.create_page_extensions Methods: create_action_buttons load_configs: Load pages except for extensions. activate_config_changes: Tell editors to reload. """ self.note = note = Notebook(self) self.highpage = HighPage(note) self.fontpage = FontPage(note, self.highpage) self.keyspage = KeysPage(note) self.genpage = GenPage(note) self.extpage = self.create_page_extensions() note.add(self.fontpage, text='Fonts/Tabs') note.add(self.highpage, text='Highlights') note.add(self.keyspage, text=' Keys ') note.add(self.genpage, text=' General ') note.add(self.extpage, text='Extensions') note.enable_traversal() note.pack(side=TOP, expand=TRUE, fill=BOTH) self.create_action_buttons().pack(side=BOTTOM)
Create and place widgets for tabbed dialog. Widgets Bound to self: note: Notebook highpage: HighPage fontpage: FontPage keyspage: KeysPage genpage: GenPage extpage: self.create_page_extensions Methods: create_action_buttons load_configs: Load pages except for extensions. activate_config_changes: Tell editors to reload.
create_widgets
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def create_action_buttons(self): """Return frame of action buttons for dialog. Methods: ok apply cancel help Widget Structure: outer: Frame buttons: Frame (no assignment): Button (ok) (no assignment): Button (apply) (no assignment): Button (cancel) (no assignment): Button (help) (no assignment): Frame """ if macosx.isAquaTk(): # Changing the default padding on OSX results in unreadable # text in the buttons. padding_args = {} else: padding_args = {'padding': (6, 3)} outer = Frame(self, padding=2) buttons_frame = Frame(outer, padding=2) self.buttons = {} for txt, cmd in ( ('Ok', self.ok), ('Apply', self.apply), ('Cancel', self.cancel), ('Help', self.help)): self.buttons[txt] = Button(buttons_frame, text=txt, command=cmd, takefocus=FALSE, **padding_args) self.buttons[txt].pack(side=LEFT, padx=5) # Add space above buttons. Frame(outer, height=2, borderwidth=0).pack(side=TOP) buttons_frame.pack(side=BOTTOM) return outer
Return frame of action buttons for dialog. Methods: ok apply cancel help Widget Structure: outer: Frame buttons: Frame (no assignment): Button (ok) (no assignment): Button (apply) (no assignment): Button (cancel) (no assignment): Button (help) (no assignment): Frame
create_action_buttons
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def ok(self): """Apply config changes, then dismiss dialog. Methods: apply destroy: inherited """ self.apply() self.destroy()
Apply config changes, then dismiss dialog. Methods: apply destroy: inherited
ok
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def apply(self): """Apply config changes and leave dialog open. Methods: deactivate_current_config save_all_changed_extensions activate_config_changes """ self.deactivate_current_config() changes.save_all() self.save_all_changed_extensions() self.activate_config_changes()
Apply config changes and leave dialog open. Methods: deactivate_current_config save_all_changed_extensions activate_config_changes
apply
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def cancel(self): """Dismiss config dialog. Methods: destroy: inherited """ changes.clear() self.destroy()
Dismiss config dialog. Methods: destroy: inherited
cancel
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def help(self): """Create textview for config dialog help. Attributes accessed: note Methods: view_text: Method from textview module. """ page = self.note.tab(self.note.select(), option='text').strip() view_text(self, title='Help for IDLE preferences', contents=help_common+help_pages.get(page, ''))
Create textview for config dialog help. Attributes accessed: note Methods: view_text: Method from textview module.
help
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def deactivate_current_config(self): """Remove current key bindings. Iterate over window instances defined in parent and remove the keybindings. """ # Before a config is saved, some cleanup of current # config must be done - remove the previous keybindings. win_instances = self.parent.instance_dict.keys() for instance in win_instances: instance.RemoveKeybindings()
Remove current key bindings. Iterate over window instances defined in parent and remove the keybindings.
deactivate_current_config
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def activate_config_changes(self): """Apply configuration changes to current windows. Dynamically update the current parent window instances with some of the configuration changes. """ win_instances = self.parent.instance_dict.keys() for instance in win_instances: instance.ResetColorizer() instance.ResetFont() instance.set_notabs_indentwidth() instance.ApplyKeybindings() instance.reset_help_menu_entries() instance.update_cursor_blink() for klass in reloadables: klass.reload()
Apply configuration changes to current windows. Dynamically update the current parent window instances with some of the configuration changes.
activate_config_changes
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def create_page_extensions(self): """Part of the config dialog used for configuring IDLE extensions. This code is generic - it works for any and all IDLE extensions. IDLE extensions save their configuration options using idleConf. This code reads the current configuration using idleConf, supplies a GUI interface to change the configuration values, and saves the changes using idleConf. Not all changes take effect immediately - some may require restarting IDLE. This depends on each extension's implementation. All values are treated as text, and it is up to the user to supply reasonable values. The only exception to this are the 'enable*' options, which are boolean, and can be toggled with a True/False button. Methods: load_extensions: extension_selected: Handle selection from list. create_extension_frame: Hold widgets for one extension. set_extension_value: Set in userCfg['extensions']. save_all_changed_extensions: Call extension page Save(). """ parent = self.parent frame = Frame(self.note) self.ext_defaultCfg = idleConf.defaultCfg['extensions'] self.ext_userCfg = idleConf.userCfg['extensions'] self.is_int = self.register(is_int) self.load_extensions() # Create widgets - a listbox shows all available extensions, with the # controls for the extension selected in the listbox to the right. self.extension_names = StringVar(self) frame.rowconfigure(0, weight=1) frame.columnconfigure(2, weight=1) self.extension_list = Listbox(frame, listvariable=self.extension_names, selectmode='browse') self.extension_list.bind('<<ListboxSelect>>', self.extension_selected) scroll = Scrollbar(frame, command=self.extension_list.yview) self.extension_list.yscrollcommand=scroll.set self.details_frame = LabelFrame(frame, width=250, height=250) self.extension_list.grid(column=0, row=0, sticky='nws') scroll.grid(column=1, row=0, sticky='ns') self.details_frame.grid(column=2, row=0, sticky='nsew', padx=[10, 0]) frame.configure(padding=10) self.config_frame = {} self.current_extension = None self.outerframe = self # TEMPORARY self.tabbed_page_set = self.extension_list # TEMPORARY # Create the frame holding controls for each extension. ext_names = '' for ext_name in sorted(self.extensions): self.create_extension_frame(ext_name) ext_names = ext_names + '{' + ext_name + '} ' self.extension_names.set(ext_names) self.extension_list.selection_set(0) self.extension_selected(None) return frame
Part of the config dialog used for configuring IDLE extensions. This code is generic - it works for any and all IDLE extensions. IDLE extensions save their configuration options using idleConf. This code reads the current configuration using idleConf, supplies a GUI interface to change the configuration values, and saves the changes using idleConf. Not all changes take effect immediately - some may require restarting IDLE. This depends on each extension's implementation. All values are treated as text, and it is up to the user to supply reasonable values. The only exception to this are the 'enable*' options, which are boolean, and can be toggled with a True/False button. Methods: load_extensions: extension_selected: Handle selection from list. create_extension_frame: Hold widgets for one extension. set_extension_value: Set in userCfg['extensions']. save_all_changed_extensions: Call extension page Save().
create_page_extensions
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def create_extension_frame(self, ext_name): """Create a frame holding the widgets to configure one extension""" f = VerticalScrolledFrame(self.details_frame, height=250, width=250) self.config_frame[ext_name] = f entry_area = f.interior # Create an entry for each configuration option. for row, opt in enumerate(self.extensions[ext_name]): # Create a row with a label and entry/checkbutton. label = Label(entry_area, text=opt['name']) label.grid(row=row, column=0, sticky=NW) var = opt['var'] if opt['type'] == 'bool': Checkbutton(entry_area, variable=var, onvalue='True', offvalue='False', width=8 ).grid(row=row, column=1, sticky=W, padx=7) elif opt['type'] == 'int': Entry(entry_area, textvariable=var, validate='key', validatecommand=(self.is_int, '%P'), width=10 ).grid(row=row, column=1, sticky=NSEW, padx=7) else: # type == 'str' # Limit size to fit non-expanding space with larger font. Entry(entry_area, textvariable=var, width=15 ).grid(row=row, column=1, sticky=NSEW, padx=7) return
Create a frame holding the widgets to configure one extension
create_extension_frame
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def set_extension_value(self, section, opt): """Return True if the configuration was added or changed. If the value is the same as the default, then remove it from user config file. """ name = opt['name'] default = opt['default'] value = opt['var'].get().strip() or default opt['var'].set(value) # if self.defaultCfg.has_section(section): # Currently, always true; if not, indent to return. if (value == default): return self.ext_userCfg.RemoveOption(section, name) # Set the option. return self.ext_userCfg.SetOption(section, name, value)
Return True if the configuration was added or changed. If the value is the same as the default, then remove it from user config file.
set_extension_value
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def save_all_changed_extensions(self): """Save configuration changes to the user config file. Attributes accessed: extensions Methods: set_extension_value """ has_changes = False for ext_name in self.extensions: options = self.extensions[ext_name] for opt in options: if self.set_extension_value(ext_name, opt): has_changes = True if has_changes: self.ext_userCfg.Save()
Save configuration changes to the user config file. Attributes accessed: extensions Methods: set_extension_value
save_all_changed_extensions
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def create_page_font_tab(self): """Return frame of widgets for Font/Tabs tab. Fonts: Enable users to provisionally change font face, size, or boldness and to see the consequence of proposed choices. Each action set 3 options in changes structuree and changes the corresponding aspect of the font sample on this page and highlight sample on highlight page. Function load_font_cfg initializes font vars and widgets from idleConf entries and tk. Fontlist: mouse button 1 click or up or down key invoke on_fontlist_select(), which sets var font_name. Sizelist: clicking the menubutton opens the dropdown menu. A mouse button 1 click or return key sets var font_size. Bold_toggle: clicking the box toggles var font_bold. Changing any of the font vars invokes var_changed_font, which adds all 3 font options to changes and calls set_samples. Set_samples applies a new font constructed from the font vars to font_sample and to highlight_sample on the highlight page. Tabs: Enable users to change spaces entered for indent tabs. Changing indent_scale value with the mouse sets Var space_num, which invokes the default callback to add an entry to changes. Load_tab_cfg initializes space_num to default. Widgets for FontPage(Frame): (*) widgets bound to self frame_font: LabelFrame frame_font_name: Frame font_name_title: Label (*)fontlist: ListBox - font_name scroll_font: Scrollbar frame_font_param: Frame font_size_title: Label (*)sizelist: DynOptionMenu - font_size (*)bold_toggle: Checkbutton - font_bold frame_sample: LabelFrame (*)font_sample: Label frame_indent: LabelFrame indent_title: Label (*)indent_scale: Scale - space_num """ self.font_name = tracers.add(StringVar(self), self.var_changed_font) self.font_size = tracers.add(StringVar(self), self.var_changed_font) self.font_bold = tracers.add(BooleanVar(self), self.var_changed_font) self.space_num = tracers.add(IntVar(self), ('main', 'Indent', 'num-spaces')) # Define frames and widgets. frame_font = LabelFrame( self, borderwidth=2, relief=GROOVE, text=' Shell/Editor Font ') frame_sample = LabelFrame( self, borderwidth=2, relief=GROOVE, text=' Font Sample (Editable) ') frame_indent = LabelFrame( self, borderwidth=2, relief=GROOVE, text=' Indentation Width ') # frame_font. frame_font_name = Frame(frame_font) frame_font_param = Frame(frame_font) font_name_title = Label( frame_font_name, justify=LEFT, text='Font Face :') self.fontlist = Listbox(frame_font_name, height=15, takefocus=True, exportselection=FALSE) self.fontlist.bind('<ButtonRelease-1>', self.on_fontlist_select) self.fontlist.bind('<KeyRelease-Up>', self.on_fontlist_select) self.fontlist.bind('<KeyRelease-Down>', self.on_fontlist_select) scroll_font = Scrollbar(frame_font_name) scroll_font.config(command=self.fontlist.yview) self.fontlist.config(yscrollcommand=scroll_font.set) font_size_title = Label(frame_font_param, text='Size :') self.sizelist = DynOptionMenu(frame_font_param, self.font_size, None) self.bold_toggle = Checkbutton( frame_font_param, variable=self.font_bold, onvalue=1, offvalue=0, text='Bold') # frame_sample. font_sample_frame = ScrollableTextFrame(frame_sample) self.font_sample = font_sample_frame.text self.font_sample.config(wrap=NONE, width=1, height=1) self.font_sample.insert(END, font_sample_text) # frame_indent. indent_title = Label( frame_indent, justify=LEFT, text='Python Standard: 4 Spaces!') self.indent_scale = Scale( frame_indent, variable=self.space_num, orient='horizontal', tickinterval=2, from_=2, to=16) # Grid and pack widgets: self.columnconfigure(1, weight=1) self.rowconfigure(2, weight=1) frame_font.grid(row=0, column=0, padx=5, pady=5) frame_sample.grid(row=0, column=1, rowspan=3, padx=5, pady=5, sticky='nsew') frame_indent.grid(row=1, column=0, padx=5, pady=5, sticky='ew') # frame_font. frame_font_name.pack(side=TOP, padx=5, pady=5, fill=X) frame_font_param.pack(side=TOP, padx=5, pady=5, fill=X) font_name_title.pack(side=TOP, anchor=W) self.fontlist.pack(side=LEFT, expand=TRUE, fill=X) scroll_font.pack(side=LEFT, fill=Y) font_size_title.pack(side=LEFT, anchor=W) self.sizelist.pack(side=LEFT, anchor=W) self.bold_toggle.pack(side=LEFT, anchor=W, padx=20) # frame_sample. font_sample_frame.pack(expand=TRUE, fill=BOTH) # frame_indent. indent_title.pack(side=TOP, anchor=W, padx=5) self.indent_scale.pack(side=TOP, padx=5, fill=X)
Return frame of widgets for Font/Tabs tab. Fonts: Enable users to provisionally change font face, size, or boldness and to see the consequence of proposed choices. Each action set 3 options in changes structuree and changes the corresponding aspect of the font sample on this page and highlight sample on highlight page. Function load_font_cfg initializes font vars and widgets from idleConf entries and tk. Fontlist: mouse button 1 click or up or down key invoke on_fontlist_select(), which sets var font_name. Sizelist: clicking the menubutton opens the dropdown menu. A mouse button 1 click or return key sets var font_size. Bold_toggle: clicking the box toggles var font_bold. Changing any of the font vars invokes var_changed_font, which adds all 3 font options to changes and calls set_samples. Set_samples applies a new font constructed from the font vars to font_sample and to highlight_sample on the highlight page. Tabs: Enable users to change spaces entered for indent tabs. Changing indent_scale value with the mouse sets Var space_num, which invokes the default callback to add an entry to changes. Load_tab_cfg initializes space_num to default. Widgets for FontPage(Frame): (*) widgets bound to self frame_font: LabelFrame frame_font_name: Frame font_name_title: Label (*)fontlist: ListBox - font_name scroll_font: Scrollbar frame_font_param: Frame font_size_title: Label (*)sizelist: DynOptionMenu - font_size (*)bold_toggle: Checkbutton - font_bold frame_sample: LabelFrame (*)font_sample: Label frame_indent: LabelFrame indent_title: Label (*)indent_scale: Scale - space_num
create_page_font_tab
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def load_font_cfg(self): """Load current configuration settings for the font options. Retrieve current font with idleConf.GetFont and font families from tk. Setup fontlist and set font_name. Setup sizelist, which sets font_size. Set font_bold. Call set_samples. """ configured_font = idleConf.GetFont(self, 'main', 'EditorWindow') font_name = configured_font[0].lower() font_size = configured_font[1] font_bold = configured_font[2]=='bold' # Set sorted no-duplicate editor font selection list and font_name. fonts = sorted(set(tkFont.families(self))) for font in fonts: self.fontlist.insert(END, font) self.font_name.set(font_name) lc_fonts = [s.lower() for s in fonts] try: current_font_index = lc_fonts.index(font_name) self.fontlist.see(current_font_index) self.fontlist.select_set(current_font_index) self.fontlist.select_anchor(current_font_index) self.fontlist.activate(current_font_index) except ValueError: pass # Set font size dropdown. self.sizelist.SetMenu(('7', '8', '9', '10', '11', '12', '13', '14', '16', '18', '20', '22', '25', '29', '34', '40'), font_size) # Set font weight. self.font_bold.set(font_bold) self.set_samples()
Load current configuration settings for the font options. Retrieve current font with idleConf.GetFont and font families from tk. Setup fontlist and set font_name. Setup sizelist, which sets font_size. Set font_bold. Call set_samples.
load_font_cfg
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def var_changed_font(self, *params): """Store changes to font attributes. When one font attribute changes, save them all, as they are not independent from each other. In particular, when we are overriding the default font, we need to write out everything. """ value = self.font_name.get() changes.add_option('main', 'EditorWindow', 'font', value) value = self.font_size.get() changes.add_option('main', 'EditorWindow', 'font-size', value) value = self.font_bold.get() changes.add_option('main', 'EditorWindow', 'font-bold', value) self.set_samples()
Store changes to font attributes. When one font attribute changes, save them all, as they are not independent from each other. In particular, when we are overriding the default font, we need to write out everything.
var_changed_font
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def on_fontlist_select(self, event): """Handle selecting a font from the list. Event can result from either mouse click or Up or Down key. Set font_name and example displays to selection. """ font = self.fontlist.get( ACTIVE if event.type.name == 'KeyRelease' else ANCHOR) self.font_name.set(font.lower())
Handle selecting a font from the list. Event can result from either mouse click or Up or Down key. Set font_name and example displays to selection.
on_fontlist_select
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def set_samples(self, event=None): """Update update both screen samples with the font settings. Called on font initialization and change events. Accesses font_name, font_size, and font_bold Variables. Updates font_sample and highlight page highlight_sample. """ font_name = self.font_name.get() font_weight = tkFont.BOLD if self.font_bold.get() else tkFont.NORMAL new_font = (font_name, self.font_size.get(), font_weight) self.font_sample['font'] = new_font self.highlight_sample['font'] = new_font
Update update both screen samples with the font settings. Called on font initialization and change events. Accesses font_name, font_size, and font_bold Variables. Updates font_sample and highlight page highlight_sample.
set_samples
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def load_tab_cfg(self): """Load current configuration settings for the tab options. Attributes updated: space_num: Set to value from idleConf. """ # Set indent sizes. space_num = idleConf.GetOption( 'main', 'Indent', 'num-spaces', default=4, type='int') self.space_num.set(space_num)
Load current configuration settings for the tab options. Attributes updated: space_num: Set to value from idleConf.
load_tab_cfg
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def create_page_highlight(self): """Return frame of widgets for Highlighting tab. Enable users to provisionally change foreground and background colors applied to textual tags. Color mappings are stored in complete listings called themes. Built-in themes in idlelib/config-highlight.def are fixed as far as the dialog is concerned. Any theme can be used as the base for a new custom theme, stored in .idlerc/config-highlight.cfg. Function load_theme_cfg() initializes tk variables and theme lists and calls paint_theme_sample() and set_highlight_target() for the current theme. Radiobuttons builtin_theme_on and custom_theme_on toggle var theme_source, which controls if the current set of colors are from a builtin or custom theme. DynOptionMenus builtinlist and customlist contain lists of the builtin and custom themes, respectively, and the current item from each list is stored in vars builtin_name and custom_name. Function paint_theme_sample() applies the colors from the theme to the tags in text widget highlight_sample and then invokes set_color_sample(). Function set_highlight_target() sets the state of the radiobuttons fg_on and bg_on based on the tag and it also invokes set_color_sample(). Function set_color_sample() sets the background color for the frame holding the color selector. This provides a larger visual of the color for the current tag and plane (foreground/background). Note: set_color_sample() is called from many places and is often called more than once when a change is made. It is invoked when foreground or background is selected (radiobuttons), from paint_theme_sample() (theme is changed or load_cfg is called), and from set_highlight_target() (target tag is changed or load_cfg called). Button delete_custom invokes delete_custom() to delete a custom theme from idleConf.userCfg['highlight'] and changes. Button save_custom invokes save_as_new_theme() which calls get_new_theme_name() and create_new() to save a custom theme and its colors to idleConf.userCfg['highlight']. Radiobuttons fg_on and bg_on toggle var fg_bg_toggle to control if the current selected color for a tag is for the foreground or background. DynOptionMenu targetlist contains a readable description of the tags applied to Python source within IDLE. Selecting one of the tags from this list populates highlight_target, which has a callback function set_highlight_target(). Text widget highlight_sample displays a block of text (which is mock Python code) in which is embedded the defined tags and reflects the color attributes of the current theme and changes for those tags. Mouse button 1 allows for selection of a tag and updates highlight_target with that tag value. Note: The font in highlight_sample is set through the config in the fonts tab. In other words, a tag can be selected either from targetlist or by clicking on the sample text within highlight_sample. The plane (foreground/background) is selected via the radiobutton. Together, these two (tag and plane) control what color is shown in set_color_sample() for the current theme. Button set_color invokes get_color() which displays a ColorChooser to change the color for the selected tag/plane. If a new color is picked, it will be saved to changes and the highlight_sample and frame background will be updated. Tk Variables: color: Color of selected target. builtin_name: Menu variable for built-in theme. custom_name: Menu variable for custom theme. fg_bg_toggle: Toggle for foreground/background color. Note: this has no callback. theme_source: Selector for built-in or custom theme. highlight_target: Menu variable for the highlight tag target. Instance Data Attributes: theme_elements: Dictionary of tags for text highlighting. The key is the display name and the value is a tuple of (tag name, display sort order). Methods [attachment]: load_theme_cfg: Load current highlight colors. get_color: Invoke colorchooser [button_set_color]. set_color_sample_binding: Call set_color_sample [fg_bg_toggle]. set_highlight_target: set fg_bg_toggle, set_color_sample(). set_color_sample: Set frame background to target. on_new_color_set: Set new color and add option. paint_theme_sample: Recolor sample. get_new_theme_name: Get from popup. create_new: Combine theme with changes and save. save_as_new_theme: Save [button_save_custom]. set_theme_type: Command for [theme_source]. delete_custom: Activate default [button_delete_custom]. save_new: Save to userCfg['theme'] (is function). Widgets of highlights page frame: (*) widgets bound to self frame_custom: LabelFrame (*)highlight_sample: Text (*)frame_color_set: Frame (*)button_set_color: Button (*)targetlist: DynOptionMenu - highlight_target frame_fg_bg_toggle: Frame (*)fg_on: Radiobutton - fg_bg_toggle (*)bg_on: Radiobutton - fg_bg_toggle (*)button_save_custom: Button frame_theme: LabelFrame theme_type_title: Label (*)builtin_theme_on: Radiobutton - theme_source (*)custom_theme_on: Radiobutton - theme_source (*)builtinlist: DynOptionMenu - builtin_name (*)customlist: DynOptionMenu - custom_name (*)button_delete_custom: Button (*)theme_message: Label """ self.theme_elements = { 'Normal Code or Text': ('normal', '00'), 'Code Context': ('context', '01'), 'Python Keywords': ('keyword', '02'), 'Python Definitions': ('definition', '03'), 'Python Builtins': ('builtin', '04'), 'Python Comments': ('comment', '05'), 'Python Strings': ('string', '06'), 'Selected Text': ('hilite', '07'), 'Found Text': ('hit', '08'), 'Cursor': ('cursor', '09'), 'Editor Breakpoint': ('break', '10'), 'Shell Prompt': ('console', '11'), 'Error Text': ('error', '12'), 'Shell User Output': ('stdout', '13'), 'Shell User Exception': ('stderr', '14'), 'Line Number': ('linenumber', '16'), } self.builtin_name = tracers.add( StringVar(self), self.var_changed_builtin_name) self.custom_name = tracers.add( StringVar(self), self.var_changed_custom_name) self.fg_bg_toggle = BooleanVar(self) self.color = tracers.add( StringVar(self), self.var_changed_color) self.theme_source = tracers.add( BooleanVar(self), self.var_changed_theme_source) self.highlight_target = tracers.add( StringVar(self), self.var_changed_highlight_target) # Create widgets: # body frame and section frames. frame_custom = LabelFrame(self, borderwidth=2, relief=GROOVE, text=' Custom Highlighting ') frame_theme = LabelFrame(self, borderwidth=2, relief=GROOVE, text=' Highlighting Theme ') # frame_custom. sample_frame = ScrollableTextFrame( frame_custom, relief=SOLID, borderwidth=1) text = self.highlight_sample = sample_frame.text text.configure( font=('courier', 12, ''), cursor='hand2', width=1, height=1, takefocus=FALSE, highlightthickness=0, wrap=NONE) # Prevent perhaps invisible selection of word or slice. text.bind('<Double-Button-1>', lambda e: 'break') text.bind('<B1-Motion>', lambda e: 'break') string_tags=( ('# Click selects item.', 'comment'), ('\n', 'normal'), ('code context section', 'context'), ('\n', 'normal'), ('| cursor', 'cursor'), ('\n', 'normal'), ('def', 'keyword'), (' ', 'normal'), ('func', 'definition'), ('(param):\n ', 'normal'), ('"Return None."', 'string'), ('\n var0 = ', 'normal'), ("'string'", 'string'), ('\n var1 = ', 'normal'), ("'selected'", 'hilite'), ('\n var2 = ', 'normal'), ("'found'", 'hit'), ('\n var3 = ', 'normal'), ('list', 'builtin'), ('(', 'normal'), ('None', 'keyword'), (')\n', 'normal'), (' breakpoint("line")', 'break'), ('\n\n', 'normal'), ('>>>', 'console'), (' 3.14**2\n', 'normal'), ('9.8596', 'stdout'), ('\n', 'normal'), ('>>>', 'console'), (' pri ', 'normal'), ('n', 'error'), ('t(\n', 'normal'), ('SyntaxError', 'stderr'), ('\n', 'normal')) for string, tag in string_tags: text.insert(END, string, tag) n_lines = len(text.get('1.0', END).splitlines()) for lineno in range(1, n_lines): text.insert(f'{lineno}.0', f'{lineno:{len(str(n_lines))}d} ', 'linenumber') for element in self.theme_elements: def tem(event, elem=element): # event.widget.winfo_top_level().highlight_target.set(elem) self.highlight_target.set(elem) text.tag_bind( self.theme_elements[element][0], '<ButtonPress-1>', tem) text['state'] = 'disabled' self.style.configure('frame_color_set.TFrame', borderwidth=1, relief='solid') self.frame_color_set = Frame(frame_custom, style='frame_color_set.TFrame') frame_fg_bg_toggle = Frame(frame_custom) self.button_set_color = Button( self.frame_color_set, text='Choose Color for :', command=self.get_color) self.targetlist = DynOptionMenu( self.frame_color_set, self.highlight_target, None, highlightthickness=0) #, command=self.set_highlight_targetBinding self.fg_on = Radiobutton( frame_fg_bg_toggle, variable=self.fg_bg_toggle, value=1, text='Foreground', command=self.set_color_sample_binding) self.bg_on = Radiobutton( frame_fg_bg_toggle, variable=self.fg_bg_toggle, value=0, text='Background', command=self.set_color_sample_binding) self.fg_bg_toggle.set(1) self.button_save_custom = Button( frame_custom, text='Save as New Custom Theme', command=self.save_as_new_theme) # frame_theme. theme_type_title = Label(frame_theme, text='Select : ') self.builtin_theme_on = Radiobutton( frame_theme, variable=self.theme_source, value=1, command=self.set_theme_type, text='a Built-in Theme') self.custom_theme_on = Radiobutton( frame_theme, variable=self.theme_source, value=0, command=self.set_theme_type, text='a Custom Theme') self.builtinlist = DynOptionMenu( frame_theme, self.builtin_name, None, command=None) self.customlist = DynOptionMenu( frame_theme, self.custom_name, None, command=None) self.button_delete_custom = Button( frame_theme, text='Delete Custom Theme', command=self.delete_custom) self.theme_message = Label(frame_theme, borderwidth=2) # Pack widgets: # body. frame_custom.pack(side=LEFT, padx=5, pady=5, expand=TRUE, fill=BOTH) frame_theme.pack(side=TOP, padx=5, pady=5, fill=X) # frame_custom. self.frame_color_set.pack(side=TOP, padx=5, pady=5, fill=X) frame_fg_bg_toggle.pack(side=TOP, padx=5, pady=0) sample_frame.pack( side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) self.button_set_color.pack(side=TOP, expand=TRUE, fill=X, padx=8, pady=4) self.targetlist.pack(side=TOP, expand=TRUE, fill=X, padx=8, pady=3) self.fg_on.pack(side=LEFT, anchor=E) self.bg_on.pack(side=RIGHT, anchor=W) self.button_save_custom.pack(side=BOTTOM, fill=X, padx=5, pady=5) # frame_theme. theme_type_title.pack(side=TOP, anchor=W, padx=5, pady=5) self.builtin_theme_on.pack(side=TOP, anchor=W, padx=5) self.custom_theme_on.pack(side=TOP, anchor=W, padx=5, pady=2) self.builtinlist.pack(side=TOP, fill=X, padx=5, pady=5) self.customlist.pack(side=TOP, fill=X, anchor=W, padx=5, pady=5) self.button_delete_custom.pack(side=TOP, fill=X, padx=5, pady=5) self.theme_message.pack(side=TOP, fill=X, pady=5)
Return frame of widgets for Highlighting tab. Enable users to provisionally change foreground and background colors applied to textual tags. Color mappings are stored in complete listings called themes. Built-in themes in idlelib/config-highlight.def are fixed as far as the dialog is concerned. Any theme can be used as the base for a new custom theme, stored in .idlerc/config-highlight.cfg. Function load_theme_cfg() initializes tk variables and theme lists and calls paint_theme_sample() and set_highlight_target() for the current theme. Radiobuttons builtin_theme_on and custom_theme_on toggle var theme_source, which controls if the current set of colors are from a builtin or custom theme. DynOptionMenus builtinlist and customlist contain lists of the builtin and custom themes, respectively, and the current item from each list is stored in vars builtin_name and custom_name. Function paint_theme_sample() applies the colors from the theme to the tags in text widget highlight_sample and then invokes set_color_sample(). Function set_highlight_target() sets the state of the radiobuttons fg_on and bg_on based on the tag and it also invokes set_color_sample(). Function set_color_sample() sets the background color for the frame holding the color selector. This provides a larger visual of the color for the current tag and plane (foreground/background). Note: set_color_sample() is called from many places and is often called more than once when a change is made. It is invoked when foreground or background is selected (radiobuttons), from paint_theme_sample() (theme is changed or load_cfg is called), and from set_highlight_target() (target tag is changed or load_cfg called). Button delete_custom invokes delete_custom() to delete a custom theme from idleConf.userCfg['highlight'] and changes. Button save_custom invokes save_as_new_theme() which calls get_new_theme_name() and create_new() to save a custom theme and its colors to idleConf.userCfg['highlight']. Radiobuttons fg_on and bg_on toggle var fg_bg_toggle to control if the current selected color for a tag is for the foreground or background. DynOptionMenu targetlist contains a readable description of the tags applied to Python source within IDLE. Selecting one of the tags from this list populates highlight_target, which has a callback function set_highlight_target(). Text widget highlight_sample displays a block of text (which is mock Python code) in which is embedded the defined tags and reflects the color attributes of the current theme and changes for those tags. Mouse button 1 allows for selection of a tag and updates highlight_target with that tag value. Note: The font in highlight_sample is set through the config in the fonts tab. In other words, a tag can be selected either from targetlist or by clicking on the sample text within highlight_sample. The plane (foreground/background) is selected via the radiobutton. Together, these two (tag and plane) control what color is shown in set_color_sample() for the current theme. Button set_color invokes get_color() which displays a ColorChooser to change the color for the selected tag/plane. If a new color is picked, it will be saved to changes and the highlight_sample and frame background will be updated. Tk Variables: color: Color of selected target. builtin_name: Menu variable for built-in theme. custom_name: Menu variable for custom theme. fg_bg_toggle: Toggle for foreground/background color. Note: this has no callback. theme_source: Selector for built-in or custom theme. highlight_target: Menu variable for the highlight tag target. Instance Data Attributes: theme_elements: Dictionary of tags for text highlighting. The key is the display name and the value is a tuple of (tag name, display sort order). Methods [attachment]: load_theme_cfg: Load current highlight colors. get_color: Invoke colorchooser [button_set_color]. set_color_sample_binding: Call set_color_sample [fg_bg_toggle]. set_highlight_target: set fg_bg_toggle, set_color_sample(). set_color_sample: Set frame background to target. on_new_color_set: Set new color and add option. paint_theme_sample: Recolor sample. get_new_theme_name: Get from popup. create_new: Combine theme with changes and save. save_as_new_theme: Save [button_save_custom]. set_theme_type: Command for [theme_source]. delete_custom: Activate default [button_delete_custom]. save_new: Save to userCfg['theme'] (is function). Widgets of highlights page frame: (*) widgets bound to self frame_custom: LabelFrame (*)highlight_sample: Text (*)frame_color_set: Frame (*)button_set_color: Button (*)targetlist: DynOptionMenu - highlight_target frame_fg_bg_toggle: Frame (*)fg_on: Radiobutton - fg_bg_toggle (*)bg_on: Radiobutton - fg_bg_toggle (*)button_save_custom: Button frame_theme: LabelFrame theme_type_title: Label (*)builtin_theme_on: Radiobutton - theme_source (*)custom_theme_on: Radiobutton - theme_source (*)builtinlist: DynOptionMenu - builtin_name (*)customlist: DynOptionMenu - custom_name (*)button_delete_custom: Button (*)theme_message: Label
create_page_highlight
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def load_theme_cfg(self): """Load current configuration settings for the theme options. Based on the theme_source toggle, the theme is set as either builtin or custom and the initial widget values reflect the current settings from idleConf. Attributes updated: theme_source: Set from idleConf. builtinlist: List of default themes from idleConf. customlist: List of custom themes from idleConf. custom_theme_on: Disabled if there are no custom themes. custom_theme: Message with additional information. targetlist: Create menu from self.theme_elements. Methods: set_theme_type paint_theme_sample set_highlight_target """ # Set current theme type radiobutton. self.theme_source.set(idleConf.GetOption( 'main', 'Theme', 'default', type='bool', default=1)) # Set current theme. current_option = idleConf.CurrentTheme() # Load available theme option menus. if self.theme_source.get(): # Default theme selected. item_list = idleConf.GetSectionList('default', 'highlight') item_list.sort() self.builtinlist.SetMenu(item_list, current_option) item_list = idleConf.GetSectionList('user', 'highlight') item_list.sort() if not item_list: self.custom_theme_on.state(('disabled',)) self.custom_name.set('- no custom themes -') else: self.customlist.SetMenu(item_list, item_list[0]) else: # User theme selected. item_list = idleConf.GetSectionList('user', 'highlight') item_list.sort() self.customlist.SetMenu(item_list, current_option) item_list = idleConf.GetSectionList('default', 'highlight') item_list.sort() self.builtinlist.SetMenu(item_list, item_list[0]) self.set_theme_type() # Load theme element option menu. theme_names = list(self.theme_elements.keys()) theme_names.sort(key=lambda x: self.theme_elements[x][1]) self.targetlist.SetMenu(theme_names, theme_names[0]) self.paint_theme_sample() self.set_highlight_target()
Load current configuration settings for the theme options. Based on the theme_source toggle, the theme is set as either builtin or custom and the initial widget values reflect the current settings from idleConf. Attributes updated: theme_source: Set from idleConf. builtinlist: List of default themes from idleConf. customlist: List of custom themes from idleConf. custom_theme_on: Disabled if there are no custom themes. custom_theme: Message with additional information. targetlist: Create menu from self.theme_elements. Methods: set_theme_type paint_theme_sample set_highlight_target
load_theme_cfg
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def var_changed_builtin_name(self, *params): """Process new builtin theme selection. Add the changed theme's name to the changed_items and recreate the sample with the values from the selected theme. """ old_themes = ('IDLE Classic', 'IDLE New') value = self.builtin_name.get() if value not in old_themes: if idleConf.GetOption('main', 'Theme', 'name') not in old_themes: changes.add_option('main', 'Theme', 'name', old_themes[0]) changes.add_option('main', 'Theme', 'name2', value) self.theme_message['text'] = 'New theme, see Help' else: changes.add_option('main', 'Theme', 'name', value) changes.add_option('main', 'Theme', 'name2', '') self.theme_message['text'] = '' self.paint_theme_sample()
Process new builtin theme selection. Add the changed theme's name to the changed_items and recreate the sample with the values from the selected theme.
var_changed_builtin_name
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def var_changed_custom_name(self, *params): """Process new custom theme selection. If a new custom theme is selected, add the name to the changed_items and apply the theme to the sample. """ value = self.custom_name.get() if value != '- no custom themes -': changes.add_option('main', 'Theme', 'name', value) self.paint_theme_sample()
Process new custom theme selection. If a new custom theme is selected, add the name to the changed_items and apply the theme to the sample.
var_changed_custom_name
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def var_changed_theme_source(self, *params): """Process toggle between builtin and custom theme. Update the default toggle value and apply the newly selected theme type. """ value = self.theme_source.get() changes.add_option('main', 'Theme', 'default', value) if value: self.var_changed_builtin_name() else: self.var_changed_custom_name()
Process toggle between builtin and custom theme. Update the default toggle value and apply the newly selected theme type.
var_changed_theme_source
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def set_theme_type(self): """Set available screen options based on builtin or custom theme. Attributes accessed: theme_source Attributes updated: builtinlist customlist button_delete_custom custom_theme_on Called from: handler for builtin_theme_on and custom_theme_on delete_custom create_new load_theme_cfg """ if self.theme_source.get(): self.builtinlist['state'] = 'normal' self.customlist['state'] = 'disabled' self.button_delete_custom.state(('disabled',)) else: self.builtinlist['state'] = 'disabled' self.custom_theme_on.state(('!disabled',)) self.customlist['state'] = 'normal' self.button_delete_custom.state(('!disabled',))
Set available screen options based on builtin or custom theme. Attributes accessed: theme_source Attributes updated: builtinlist customlist button_delete_custom custom_theme_on Called from: handler for builtin_theme_on and custom_theme_on delete_custom create_new load_theme_cfg
set_theme_type
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def get_color(self): """Handle button to select a new color for the target tag. If a new color is selected while using a builtin theme, a name must be supplied to create a custom theme. Attributes accessed: highlight_target frame_color_set theme_source Attributes updated: color Methods: get_new_theme_name create_new """ target = self.highlight_target.get() prev_color = self.style.lookup(self.frame_color_set['style'], 'background') rgbTuplet, color_string = tkColorChooser.askcolor( parent=self, title='Pick new color for : '+target, initialcolor=prev_color) if color_string and (color_string != prev_color): # User didn't cancel and they chose a new color. if self.theme_source.get(): # Current theme is a built-in. message = ('Your changes will be saved as a new Custom Theme. ' 'Enter a name for your new Custom Theme below.') new_theme = self.get_new_theme_name(message) if not new_theme: # User cancelled custom theme creation. return else: # Create new custom theme based on previously active theme. self.create_new(new_theme) self.color.set(color_string) else: # Current theme is user defined. self.color.set(color_string)
Handle button to select a new color for the target tag. If a new color is selected while using a builtin theme, a name must be supplied to create a custom theme. Attributes accessed: highlight_target frame_color_set theme_source Attributes updated: color Methods: get_new_theme_name create_new
get_color
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def save_as_new_theme(self): """Prompt for new theme name and create the theme. Methods: get_new_theme_name create_new """ new_theme_name = self.get_new_theme_name('New Theme Name:') if new_theme_name: self.create_new(new_theme_name)
Prompt for new theme name and create the theme. Methods: get_new_theme_name create_new
save_as_new_theme
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def create_new(self, new_theme_name): """Create a new custom theme with the given name. Create the new theme based on the previously active theme with the current changes applied. Once it is saved, then activate the new theme. Attributes accessed: builtin_name custom_name Attributes updated: customlist theme_source Method: save_new set_theme_type """ if self.theme_source.get(): theme_type = 'default' theme_name = self.builtin_name.get() else: theme_type = 'user' theme_name = self.custom_name.get() new_theme = idleConf.GetThemeDict(theme_type, theme_name) # Apply any of the old theme's unsaved changes to the new theme. if theme_name in changes['highlight']: theme_changes = changes['highlight'][theme_name] for element in theme_changes: new_theme[element] = theme_changes[element] # Save the new theme. self.save_new(new_theme_name, new_theme) # Change GUI over to the new theme. custom_theme_list = idleConf.GetSectionList('user', 'highlight') custom_theme_list.sort() self.customlist.SetMenu(custom_theme_list, new_theme_name) self.theme_source.set(0) self.set_theme_type()
Create a new custom theme with the given name. Create the new theme based on the previously active theme with the current changes applied. Once it is saved, then activate the new theme. Attributes accessed: builtin_name custom_name Attributes updated: customlist theme_source Method: save_new set_theme_type
create_new
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def set_highlight_target(self): """Set fg/bg toggle and color based on highlight tag target. Instance variables accessed: highlight_target Attributes updated: fg_on bg_on fg_bg_toggle Methods: set_color_sample Called from: var_changed_highlight_target load_theme_cfg """ if self.highlight_target.get() == 'Cursor': # bg not possible self.fg_on.state(('disabled',)) self.bg_on.state(('disabled',)) self.fg_bg_toggle.set(1) else: # Both fg and bg can be set. self.fg_on.state(('!disabled',)) self.bg_on.state(('!disabled',)) self.fg_bg_toggle.set(1) self.set_color_sample()
Set fg/bg toggle and color based on highlight tag target. Instance variables accessed: highlight_target Attributes updated: fg_on bg_on fg_bg_toggle Methods: set_color_sample Called from: var_changed_highlight_target load_theme_cfg
set_highlight_target
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def set_color_sample_binding(self, *args): """Change color sample based on foreground/background toggle. Methods: set_color_sample """ self.set_color_sample()
Change color sample based on foreground/background toggle. Methods: set_color_sample
set_color_sample_binding
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def set_color_sample(self): """Set the color of the frame background to reflect the selected target. Instance variables accessed: theme_elements highlight_target fg_bg_toggle highlight_sample Attributes updated: frame_color_set """ # Set the color sample area. tag = self.theme_elements[self.highlight_target.get()][0] plane = 'foreground' if self.fg_bg_toggle.get() else 'background' color = self.highlight_sample.tag_cget(tag, plane) self.style.configure('frame_color_set.TFrame', background=color)
Set the color of the frame background to reflect the selected target. Instance variables accessed: theme_elements highlight_target fg_bg_toggle highlight_sample Attributes updated: frame_color_set
set_color_sample
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def paint_theme_sample(self): """Apply the theme colors to each element tag in the sample text. Instance attributes accessed: theme_elements theme_source builtin_name custom_name Attributes updated: highlight_sample: Set the tag elements to the theme. Methods: set_color_sample Called from: var_changed_builtin_name var_changed_custom_name load_theme_cfg """ if self.theme_source.get(): # Default theme theme = self.builtin_name.get() else: # User theme theme = self.custom_name.get() for element_title in self.theme_elements: element = self.theme_elements[element_title][0] colors = idleConf.GetHighlight(theme, element) if element == 'cursor': # Cursor sample needs special painting. colors['background'] = idleConf.GetHighlight( theme, 'normal')['background'] # Handle any unsaved changes to this theme. if theme in changes['highlight']: theme_dict = changes['highlight'][theme] if element + '-foreground' in theme_dict: colors['foreground'] = theme_dict[element + '-foreground'] if element + '-background' in theme_dict: colors['background'] = theme_dict[element + '-background'] self.highlight_sample.tag_config(element, **colors) self.set_color_sample()
Apply the theme colors to each element tag in the sample text. Instance attributes accessed: theme_elements theme_source builtin_name custom_name Attributes updated: highlight_sample: Set the tag elements to the theme. Methods: set_color_sample Called from: var_changed_builtin_name var_changed_custom_name load_theme_cfg
paint_theme_sample
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def save_new(self, theme_name, theme): """Save a newly created theme to idleConf. theme_name - string, the name of the new theme theme - dictionary containing the new theme """ idleConf.userCfg['highlight'].AddSection(theme_name) for element in theme: value = theme[element] idleConf.userCfg['highlight'].SetOption(theme_name, element, value)
Save a newly created theme to idleConf. theme_name - string, the name of the new theme theme - dictionary containing the new theme
save_new
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def delete_custom(self): """Handle event to delete custom theme. The current theme is deactivated and the default theme is activated. The custom theme is permanently removed from the config file. Attributes accessed: custom_name Attributes updated: custom_theme_on customlist theme_source builtin_name Methods: deactivate_current_config save_all_changed_extensions activate_config_changes set_theme_type """ theme_name = self.custom_name.get() delmsg = 'Are you sure you wish to delete the theme %r ?' if not self.askyesno( 'Delete Theme', delmsg % theme_name, parent=self): return self.cd.deactivate_current_config() # Remove theme from changes, config, and file. changes.delete_section('highlight', theme_name) # Reload user theme list. item_list = idleConf.GetSectionList('user', 'highlight') item_list.sort() if not item_list: self.custom_theme_on.state(('disabled',)) self.customlist.SetMenu(item_list, '- no custom themes -') else: self.customlist.SetMenu(item_list, item_list[0]) # Revert to default theme. self.theme_source.set(idleConf.defaultCfg['main'].Get('Theme', 'default')) self.builtin_name.set(idleConf.defaultCfg['main'].Get('Theme', 'name')) # User can't back out of these changes, they must be applied now. changes.save_all() self.cd.save_all_changed_extensions() self.cd.activate_config_changes() self.set_theme_type()
Handle event to delete custom theme. The current theme is deactivated and the default theme is activated. The custom theme is permanently removed from the config file. Attributes accessed: custom_name Attributes updated: custom_theme_on customlist theme_source builtin_name Methods: deactivate_current_config save_all_changed_extensions activate_config_changes set_theme_type
delete_custom
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def create_page_keys(self): """Return frame of widgets for Keys tab. Enable users to provisionally change both individual and sets of keybindings (shortcut keys). Except for features implemented as extensions, keybindings are stored in complete sets called keysets. Built-in keysets in idlelib/config-keys.def are fixed as far as the dialog is concerned. Any keyset can be used as the base for a new custom keyset, stored in .idlerc/config-keys.cfg. Function load_key_cfg() initializes tk variables and keyset lists and calls load_keys_list for the current keyset. Radiobuttons builtin_keyset_on and custom_keyset_on toggle var keyset_source, which controls if the current set of keybindings are from a builtin or custom keyset. DynOptionMenus builtinlist and customlist contain lists of the builtin and custom keysets, respectively, and the current item from each list is stored in vars builtin_name and custom_name. Button delete_custom_keys invokes delete_custom_keys() to delete a custom keyset from idleConf.userCfg['keys'] and changes. Button save_custom_keys invokes save_as_new_key_set() which calls get_new_keys_name() and create_new_key_set() to save a custom keyset and its keybindings to idleConf.userCfg['keys']. Listbox bindingslist contains all of the keybindings for the selected keyset. The keybindings are loaded in load_keys_list() and are pairs of (event, [keys]) where keys can be a list of one or more key combinations to bind to the same event. Mouse button 1 click invokes on_bindingslist_select(), which allows button_new_keys to be clicked. So, an item is selected in listbindings, which activates button_new_keys, and clicking button_new_keys calls function get_new_keys(). Function get_new_keys() gets the key mappings from the current keyset for the binding event item that was selected. The function then displays another dialog, GetKeysDialog, with the selected binding event and current keys and allows new key sequences to be entered for that binding event. If the keys aren't changed, nothing happens. If the keys are changed and the keyset is a builtin, function get_new_keys_name() will be called for input of a custom keyset name. If no name is given, then the change to the keybinding will abort and no updates will be made. If a custom name is entered in the prompt or if the current keyset was already custom (and thus didn't require a prompt), then idleConf.userCfg['keys'] is updated in function create_new_key_set() with the change to the event binding. The item listing in bindingslist is updated with the new keys. Var keybinding is also set which invokes the callback function, var_changed_keybinding, to add the change to the 'keys' or 'extensions' changes tracker based on the binding type. Tk Variables: keybinding: Action/key bindings. Methods: load_keys_list: Reload active set. create_new_key_set: Combine active keyset and changes. set_keys_type: Command for keyset_source. save_new_key_set: Save to idleConf.userCfg['keys'] (is function). deactivate_current_config: Remove keys bindings in editors. Widgets for KeysPage(frame): (*) widgets bound to self frame_key_sets: LabelFrame frames[0]: Frame (*)builtin_keyset_on: Radiobutton - var keyset_source (*)custom_keyset_on: Radiobutton - var keyset_source (*)builtinlist: DynOptionMenu - var builtin_name, func keybinding_selected (*)customlist: DynOptionMenu - var custom_name, func keybinding_selected (*)keys_message: Label frames[1]: Frame (*)button_delete_custom_keys: Button - delete_custom_keys (*)button_save_custom_keys: Button - save_as_new_key_set frame_custom: LabelFrame frame_target: Frame target_title: Label scroll_target_y: Scrollbar scroll_target_x: Scrollbar (*)bindingslist: ListBox - on_bindingslist_select (*)button_new_keys: Button - get_new_keys & ..._name """ self.builtin_name = tracers.add( StringVar(self), self.var_changed_builtin_name) self.custom_name = tracers.add( StringVar(self), self.var_changed_custom_name) self.keyset_source = tracers.add( BooleanVar(self), self.var_changed_keyset_source) self.keybinding = tracers.add( StringVar(self), self.var_changed_keybinding) # Create widgets: # body and section frames. frame_custom = LabelFrame( self, borderwidth=2, relief=GROOVE, text=' Custom Key Bindings ') frame_key_sets = LabelFrame( self, borderwidth=2, relief=GROOVE, text=' Key Set ') # frame_custom. frame_target = Frame(frame_custom) target_title = Label(frame_target, text='Action - Key(s)') scroll_target_y = Scrollbar(frame_target) scroll_target_x = Scrollbar(frame_target, orient=HORIZONTAL) self.bindingslist = Listbox( frame_target, takefocus=FALSE, exportselection=FALSE) self.bindingslist.bind('<ButtonRelease-1>', self.on_bindingslist_select) scroll_target_y['command'] = self.bindingslist.yview scroll_target_x['command'] = self.bindingslist.xview self.bindingslist['yscrollcommand'] = scroll_target_y.set self.bindingslist['xscrollcommand'] = scroll_target_x.set self.button_new_keys = Button( frame_custom, text='Get New Keys for Selection', command=self.get_new_keys, state='disabled') # frame_key_sets. frames = [Frame(frame_key_sets, padding=2, borderwidth=0) for i in range(2)] self.builtin_keyset_on = Radiobutton( frames[0], variable=self.keyset_source, value=1, command=self.set_keys_type, text='Use a Built-in Key Set') self.custom_keyset_on = Radiobutton( frames[0], variable=self.keyset_source, value=0, command=self.set_keys_type, text='Use a Custom Key Set') self.builtinlist = DynOptionMenu( frames[0], self.builtin_name, None, command=None) self.customlist = DynOptionMenu( frames[0], self.custom_name, None, command=None) self.button_delete_custom_keys = Button( frames[1], text='Delete Custom Key Set', command=self.delete_custom_keys) self.button_save_custom_keys = Button( frames[1], text='Save as New Custom Key Set', command=self.save_as_new_key_set) self.keys_message = Label(frames[0], borderwidth=2) # Pack widgets: # body. frame_custom.pack(side=BOTTOM, padx=5, pady=5, expand=TRUE, fill=BOTH) frame_key_sets.pack(side=BOTTOM, padx=5, pady=5, fill=BOTH) # frame_custom. self.button_new_keys.pack(side=BOTTOM, fill=X, padx=5, pady=5) frame_target.pack(side=LEFT, padx=5, pady=5, expand=TRUE, fill=BOTH) # frame_target. frame_target.columnconfigure(0, weight=1) frame_target.rowconfigure(1, weight=1) target_title.grid(row=0, column=0, columnspan=2, sticky=W) self.bindingslist.grid(row=1, column=0, sticky=NSEW) scroll_target_y.grid(row=1, column=1, sticky=NS) scroll_target_x.grid(row=2, column=0, sticky=EW) # frame_key_sets. self.builtin_keyset_on.grid(row=0, column=0, sticky=W+NS) self.custom_keyset_on.grid(row=1, column=0, sticky=W+NS) self.builtinlist.grid(row=0, column=1, sticky=NSEW) self.customlist.grid(row=1, column=1, sticky=NSEW) self.keys_message.grid(row=0, column=2, sticky=NSEW, padx=5, pady=5) self.button_delete_custom_keys.pack(side=LEFT, fill=X, expand=True, padx=2) self.button_save_custom_keys.pack(side=LEFT, fill=X, expand=True, padx=2) frames[0].pack(side=TOP, fill=BOTH, expand=True) frames[1].pack(side=TOP, fill=X, expand=True, pady=2)
Return frame of widgets for Keys tab. Enable users to provisionally change both individual and sets of keybindings (shortcut keys). Except for features implemented as extensions, keybindings are stored in complete sets called keysets. Built-in keysets in idlelib/config-keys.def are fixed as far as the dialog is concerned. Any keyset can be used as the base for a new custom keyset, stored in .idlerc/config-keys.cfg. Function load_key_cfg() initializes tk variables and keyset lists and calls load_keys_list for the current keyset. Radiobuttons builtin_keyset_on and custom_keyset_on toggle var keyset_source, which controls if the current set of keybindings are from a builtin or custom keyset. DynOptionMenus builtinlist and customlist contain lists of the builtin and custom keysets, respectively, and the current item from each list is stored in vars builtin_name and custom_name. Button delete_custom_keys invokes delete_custom_keys() to delete a custom keyset from idleConf.userCfg['keys'] and changes. Button save_custom_keys invokes save_as_new_key_set() which calls get_new_keys_name() and create_new_key_set() to save a custom keyset and its keybindings to idleConf.userCfg['keys']. Listbox bindingslist contains all of the keybindings for the selected keyset. The keybindings are loaded in load_keys_list() and are pairs of (event, [keys]) where keys can be a list of one or more key combinations to bind to the same event. Mouse button 1 click invokes on_bindingslist_select(), which allows button_new_keys to be clicked. So, an item is selected in listbindings, which activates button_new_keys, and clicking button_new_keys calls function get_new_keys(). Function get_new_keys() gets the key mappings from the current keyset for the binding event item that was selected. The function then displays another dialog, GetKeysDialog, with the selected binding event and current keys and allows new key sequences to be entered for that binding event. If the keys aren't changed, nothing happens. If the keys are changed and the keyset is a builtin, function get_new_keys_name() will be called for input of a custom keyset name. If no name is given, then the change to the keybinding will abort and no updates will be made. If a custom name is entered in the prompt or if the current keyset was already custom (and thus didn't require a prompt), then idleConf.userCfg['keys'] is updated in function create_new_key_set() with the change to the event binding. The item listing in bindingslist is updated with the new keys. Var keybinding is also set which invokes the callback function, var_changed_keybinding, to add the change to the 'keys' or 'extensions' changes tracker based on the binding type. Tk Variables: keybinding: Action/key bindings. Methods: load_keys_list: Reload active set. create_new_key_set: Combine active keyset and changes. set_keys_type: Command for keyset_source. save_new_key_set: Save to idleConf.userCfg['keys'] (is function). deactivate_current_config: Remove keys bindings in editors. Widgets for KeysPage(frame): (*) widgets bound to self frame_key_sets: LabelFrame frames[0]: Frame (*)builtin_keyset_on: Radiobutton - var keyset_source (*)custom_keyset_on: Radiobutton - var keyset_source (*)builtinlist: DynOptionMenu - var builtin_name, func keybinding_selected (*)customlist: DynOptionMenu - var custom_name, func keybinding_selected (*)keys_message: Label frames[1]: Frame (*)button_delete_custom_keys: Button - delete_custom_keys (*)button_save_custom_keys: Button - save_as_new_key_set frame_custom: LabelFrame frame_target: Frame target_title: Label scroll_target_y: Scrollbar scroll_target_x: Scrollbar (*)bindingslist: ListBox - on_bindingslist_select (*)button_new_keys: Button - get_new_keys & ..._name
create_page_keys
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def get_new_keys(self): """Handle event to change key binding for selected line. A selection of a key/binding in the list of current bindings pops up a dialog to enter a new binding. If the current key set is builtin and a binding has changed, then a name for a custom key set needs to be entered for the change to be applied. """ list_index = self.bindingslist.index(ANCHOR) binding = self.bindingslist.get(list_index) bind_name = binding.split()[0] if self.keyset_source.get(): current_key_set_name = self.builtin_name.get() else: current_key_set_name = self.custom_name.get() current_bindings = idleConf.GetCurrentKeySet() if current_key_set_name in changes['keys']: # unsaved changes key_set_changes = changes['keys'][current_key_set_name] for event in key_set_changes: current_bindings[event] = key_set_changes[event].split() current_key_sequences = list(current_bindings.values()) new_keys = GetKeysDialog(self, 'Get New Keys', bind_name, current_key_sequences).result if new_keys: if self.keyset_source.get(): # Current key set is a built-in. message = ('Your changes will be saved as a new Custom Key Set.' ' Enter a name for your new Custom Key Set below.') new_keyset = self.get_new_keys_name(message) if not new_keyset: # User cancelled custom key set creation. self.bindingslist.select_set(list_index) self.bindingslist.select_anchor(list_index) return else: # Create new custom key set based on previously active key set. self.create_new_key_set(new_keyset) self.bindingslist.delete(list_index) self.bindingslist.insert(list_index, bind_name+' - '+new_keys) self.bindingslist.select_set(list_index) self.bindingslist.select_anchor(list_index) self.keybinding.set(new_keys) else: self.bindingslist.select_set(list_index) self.bindingslist.select_anchor(list_index)
Handle event to change key binding for selected line. A selection of a key/binding in the list of current bindings pops up a dialog to enter a new binding. If the current key set is builtin and a binding has changed, then a name for a custom key set needs to be entered for the change to be applied.
get_new_keys
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def create_new_key_set(self, new_key_set_name): """Create a new custom key set with the given name. Copy the bindings/keys from the previously active keyset to the new keyset and activate the new custom keyset. """ if self.keyset_source.get(): prev_key_set_name = self.builtin_name.get() else: prev_key_set_name = self.custom_name.get() prev_keys = idleConf.GetCoreKeys(prev_key_set_name) new_keys = {} for event in prev_keys: # Add key set to changed items. event_name = event[2:-2] # Trim off the angle brackets. binding = ' '.join(prev_keys[event]) new_keys[event_name] = binding # Handle any unsaved changes to prev key set. if prev_key_set_name in changes['keys']: key_set_changes = changes['keys'][prev_key_set_name] for event in key_set_changes: new_keys[event] = key_set_changes[event] # Save the new key set. self.save_new_key_set(new_key_set_name, new_keys) # Change GUI over to the new key set. custom_key_list = idleConf.GetSectionList('user', 'keys') custom_key_list.sort() self.customlist.SetMenu(custom_key_list, new_key_set_name) self.keyset_source.set(0) self.set_keys_type()
Create a new custom key set with the given name. Copy the bindings/keys from the previously active keyset to the new keyset and activate the new custom keyset.
create_new_key_set
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def load_keys_list(self, keyset_name): """Reload the list of action/key binding pairs for the active key set. An action/key binding can be selected to change the key binding. """ reselect = False if self.bindingslist.curselection(): reselect = True list_index = self.bindingslist.index(ANCHOR) keyset = idleConf.GetKeySet(keyset_name) bind_names = list(keyset.keys()) bind_names.sort() self.bindingslist.delete(0, END) for bind_name in bind_names: key = ' '.join(keyset[bind_name]) bind_name = bind_name[2:-2] # Trim off the angle brackets. if keyset_name in changes['keys']: # Handle any unsaved changes to this key set. if bind_name in changes['keys'][keyset_name]: key = changes['keys'][keyset_name][bind_name] self.bindingslist.insert(END, bind_name+' - '+key) if reselect: self.bindingslist.see(list_index) self.bindingslist.select_set(list_index) self.bindingslist.select_anchor(list_index)
Reload the list of action/key binding pairs for the active key set. An action/key binding can be selected to change the key binding.
load_keys_list
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def save_new_key_set(keyset_name, keyset): """Save a newly created core key set. Add keyset to idleConf.userCfg['keys'], not to disk. If the keyset doesn't exist, it is created. The binding/keys are taken from the keyset argument. keyset_name - string, the name of the new key set keyset - dictionary containing the new keybindings """ idleConf.userCfg['keys'].AddSection(keyset_name) for event in keyset: value = keyset[event] idleConf.userCfg['keys'].SetOption(keyset_name, event, value)
Save a newly created core key set. Add keyset to idleConf.userCfg['keys'], not to disk. If the keyset doesn't exist, it is created. The binding/keys are taken from the keyset argument. keyset_name - string, the name of the new key set keyset - dictionary containing the new keybindings
save_new_key_set
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def delete_custom_keys(self): """Handle event to delete a custom key set. Applying the delete deactivates the current configuration and reverts to the default. The custom key set is permanently deleted from the config file. """ keyset_name = self.custom_name.get() delmsg = 'Are you sure you wish to delete the key set %r ?' if not self.askyesno( 'Delete Key Set', delmsg % keyset_name, parent=self): return self.cd.deactivate_current_config() # Remove key set from changes, config, and file. changes.delete_section('keys', keyset_name) # Reload user key set list. item_list = idleConf.GetSectionList('user', 'keys') item_list.sort() if not item_list: self.custom_keyset_on.state(('disabled',)) self.customlist.SetMenu(item_list, '- no custom keys -') else: self.customlist.SetMenu(item_list, item_list[0]) # Revert to default key set. self.keyset_source.set(idleConf.defaultCfg['main'] .Get('Keys', 'default')) self.builtin_name.set(idleConf.defaultCfg['main'].Get('Keys', 'name') or idleConf.default_keys()) # User can't back out of these changes, they must be applied now. changes.save_all() self.cd.save_all_changed_extensions() self.cd.activate_config_changes() self.set_keys_type()
Handle event to delete a custom key set. Applying the delete deactivates the current configuration and reverts to the default. The custom key set is permanently deleted from the config file.
delete_custom_keys
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def create_page_general(self): """Return frame of widgets for General tab. Enable users to provisionally change general options. Function load_general_cfg initializes tk variables and helplist using idleConf. Radiobuttons startup_shell_on and startup_editor_on set var startup_edit. Radiobuttons save_ask_on and save_auto_on set var autosave. Entry boxes win_width_int and win_height_int set var win_width and win_height. Setting var_name invokes the default callback that adds option to changes. Helplist: load_general_cfg loads list user_helplist with name, position pairs and copies names to listbox helplist. Clicking a name invokes help_source selected. Clicking button_helplist_name invokes helplist_item_name, which also changes user_helplist. These functions all call set_add_delete_state. All but load call update_help_changes to rewrite changes['main']['HelpFiles']. Widgets for GenPage(Frame): (*) widgets bound to self frame_window: LabelFrame frame_run: Frame startup_title: Label (*)startup_editor_on: Radiobutton - startup_edit (*)startup_shell_on: Radiobutton - startup_edit frame_win_size: Frame win_size_title: Label win_width_title: Label (*)win_width_int: Entry - win_width win_height_title: Label (*)win_height_int: Entry - win_height frame_cursor_blink: Frame cursor_blink_title: Label (*)cursor_blink_bool: Checkbutton - cursor_blink frame_autocomplete: Frame auto_wait_title: Label (*)auto_wait_int: Entry - autocomplete_wait frame_paren1: Frame paren_style_title: Label (*)paren_style_type: OptionMenu - paren_style frame_paren2: Frame paren_time_title: Label (*)paren_flash_time: Entry - flash_delay (*)bell_on: Checkbutton - paren_bell frame_editor: LabelFrame frame_save: Frame run_save_title: Label (*)save_ask_on: Radiobutton - autosave (*)save_auto_on: Radiobutton - autosave frame_format: Frame format_width_title: Label (*)format_width_int: Entry - format_width frame_line_numbers_default: Frame line_numbers_default_title: Label (*)line_numbers_default_bool: Checkbutton - line_numbers_default frame_context: Frame context_title: Label (*)context_int: Entry - context_lines frame_shell: LabelFrame frame_auto_squeeze_min_lines: Frame auto_squeeze_min_lines_title: Label (*)auto_squeeze_min_lines_int: Entry - auto_squeeze_min_lines frame_help: LabelFrame frame_helplist: Frame frame_helplist_buttons: Frame (*)button_helplist_edit (*)button_helplist_add (*)button_helplist_remove (*)helplist: ListBox scroll_helplist: Scrollbar """ # Integer values need StringVar because int('') raises. self.startup_edit = tracers.add( IntVar(self), ('main', 'General', 'editor-on-startup')) self.win_width = tracers.add( StringVar(self), ('main', 'EditorWindow', 'width')) self.win_height = tracers.add( StringVar(self), ('main', 'EditorWindow', 'height')) self.cursor_blink = tracers.add( BooleanVar(self), ('main', 'EditorWindow', 'cursor-blink')) self.autocomplete_wait = tracers.add( StringVar(self), ('extensions', 'AutoComplete', 'popupwait')) self.paren_style = tracers.add( StringVar(self), ('extensions', 'ParenMatch', 'style')) self.flash_delay = tracers.add( StringVar(self), ('extensions', 'ParenMatch', 'flash-delay')) self.paren_bell = tracers.add( BooleanVar(self), ('extensions', 'ParenMatch', 'bell')) self.auto_squeeze_min_lines = tracers.add( StringVar(self), ('main', 'PyShell', 'auto-squeeze-min-lines')) self.autosave = tracers.add( IntVar(self), ('main', 'General', 'autosave')) self.format_width = tracers.add( StringVar(self), ('extensions', 'FormatParagraph', 'max-width')) self.line_numbers_default = tracers.add( BooleanVar(self), ('main', 'EditorWindow', 'line-numbers-default')) self.context_lines = tracers.add( StringVar(self), ('extensions', 'CodeContext', 'maxlines')) # Create widgets: # Section frames. frame_window = LabelFrame(self, borderwidth=2, relief=GROOVE, text=' Window Preferences') frame_editor = LabelFrame(self, borderwidth=2, relief=GROOVE, text=' Editor Preferences') frame_shell = LabelFrame(self, borderwidth=2, relief=GROOVE, text=' Shell Preferences') frame_help = LabelFrame(self, borderwidth=2, relief=GROOVE, text=' Additional Help Sources ') # Frame_window. frame_run = Frame(frame_window, borderwidth=0) startup_title = Label(frame_run, text='At Startup') self.startup_editor_on = Radiobutton( frame_run, variable=self.startup_edit, value=1, text="Open Edit Window") self.startup_shell_on = Radiobutton( frame_run, variable=self.startup_edit, value=0, text='Open Shell Window') frame_win_size = Frame(frame_window, borderwidth=0) win_size_title = Label( frame_win_size, text='Initial Window Size (in characters)') win_width_title = Label(frame_win_size, text='Width') self.win_width_int = Entry( frame_win_size, textvariable=self.win_width, width=3, validatecommand=self.digits_only, validate='key', ) win_height_title = Label(frame_win_size, text='Height') self.win_height_int = Entry( frame_win_size, textvariable=self.win_height, width=3, validatecommand=self.digits_only, validate='key', ) frame_cursor_blink = Frame(frame_window, borderwidth=0) cursor_blink_title = Label(frame_cursor_blink, text='Cursor Blink') self.cursor_blink_bool = Checkbutton(frame_cursor_blink, variable=self.cursor_blink, width=1) frame_autocomplete = Frame(frame_window, borderwidth=0,) auto_wait_title = Label(frame_autocomplete, text='Completions Popup Wait (milliseconds)') self.auto_wait_int = Entry(frame_autocomplete, width=6, textvariable=self.autocomplete_wait, validatecommand=self.digits_only, validate='key', ) frame_paren1 = Frame(frame_window, borderwidth=0) paren_style_title = Label(frame_paren1, text='Paren Match Style') self.paren_style_type = OptionMenu( frame_paren1, self.paren_style, 'expression', "opener","parens","expression") frame_paren2 = Frame(frame_window, borderwidth=0) paren_time_title = Label( frame_paren2, text='Time Match Displayed (milliseconds)\n' '(0 is until next input)') self.paren_flash_time = Entry( frame_paren2, textvariable=self.flash_delay, width=6) self.bell_on = Checkbutton( frame_paren2, text="Bell on Mismatch", variable=self.paren_bell) # Frame_editor. frame_save = Frame(frame_editor, borderwidth=0) run_save_title = Label(frame_save, text='At Start of Run (F5) ') self.save_ask_on = Radiobutton( frame_save, variable=self.autosave, value=0, text="Prompt to Save") self.save_auto_on = Radiobutton( frame_save, variable=self.autosave, value=1, text='No Prompt') frame_format = Frame(frame_editor, borderwidth=0) format_width_title = Label(frame_format, text='Format Paragraph Max Width') self.format_width_int = Entry( frame_format, textvariable=self.format_width, width=4, validatecommand=self.digits_only, validate='key', ) frame_line_numbers_default = Frame(frame_editor, borderwidth=0) line_numbers_default_title = Label( frame_line_numbers_default, text='Show line numbers in new windows') self.line_numbers_default_bool = Checkbutton( frame_line_numbers_default, variable=self.line_numbers_default, width=1) frame_context = Frame(frame_editor, borderwidth=0) context_title = Label(frame_context, text='Max Context Lines :') self.context_int = Entry( frame_context, textvariable=self.context_lines, width=3, validatecommand=self.digits_only, validate='key', ) # Frame_shell. frame_auto_squeeze_min_lines = Frame(frame_shell, borderwidth=0) auto_squeeze_min_lines_title = Label(frame_auto_squeeze_min_lines, text='Auto-Squeeze Min. Lines:') self.auto_squeeze_min_lines_int = Entry( frame_auto_squeeze_min_lines, width=4, textvariable=self.auto_squeeze_min_lines, validatecommand=self.digits_only, validate='key', ) # frame_help. frame_helplist = Frame(frame_help) frame_helplist_buttons = Frame(frame_helplist) self.helplist = Listbox( frame_helplist, height=5, takefocus=True, exportselection=FALSE) scroll_helplist = Scrollbar(frame_helplist) scroll_helplist['command'] = self.helplist.yview self.helplist['yscrollcommand'] = scroll_helplist.set self.helplist.bind('<ButtonRelease-1>', self.help_source_selected) self.button_helplist_edit = Button( frame_helplist_buttons, text='Edit', state='disabled', width=8, command=self.helplist_item_edit) self.button_helplist_add = Button( frame_helplist_buttons, text='Add', width=8, command=self.helplist_item_add) self.button_helplist_remove = Button( frame_helplist_buttons, text='Remove', state='disabled', width=8, command=self.helplist_item_remove) # Pack widgets: # Body. frame_window.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) frame_editor.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) frame_shell.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) frame_help.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) # frame_run. frame_run.pack(side=TOP, padx=5, pady=0, fill=X) startup_title.pack(side=LEFT, anchor=W, padx=5, pady=5) self.startup_shell_on.pack(side=RIGHT, anchor=W, padx=5, pady=5) self.startup_editor_on.pack(side=RIGHT, anchor=W, padx=5, pady=5) # frame_win_size. frame_win_size.pack(side=TOP, padx=5, pady=0, fill=X) win_size_title.pack(side=LEFT, anchor=W, padx=5, pady=5) self.win_height_int.pack(side=RIGHT, anchor=E, padx=10, pady=5) win_height_title.pack(side=RIGHT, anchor=E, pady=5) self.win_width_int.pack(side=RIGHT, anchor=E, padx=10, pady=5) win_width_title.pack(side=RIGHT, anchor=E, pady=5) # frame_cursor_blink. frame_cursor_blink.pack(side=TOP, padx=5, pady=0, fill=X) cursor_blink_title.pack(side=LEFT, anchor=W, padx=5, pady=5) self.cursor_blink_bool.pack(side=LEFT, padx=5, pady=5) # frame_autocomplete. frame_autocomplete.pack(side=TOP, padx=5, pady=0, fill=X) auto_wait_title.pack(side=LEFT, anchor=W, padx=5, pady=5) self.auto_wait_int.pack(side=TOP, padx=10, pady=5) # frame_paren. frame_paren1.pack(side=TOP, padx=5, pady=0, fill=X) paren_style_title.pack(side=LEFT, anchor=W, padx=5, pady=5) self.paren_style_type.pack(side=TOP, padx=10, pady=5) frame_paren2.pack(side=TOP, padx=5, pady=0, fill=X) paren_time_title.pack(side=LEFT, anchor=W, padx=5) self.bell_on.pack(side=RIGHT, anchor=E, padx=15, pady=5) self.paren_flash_time.pack(side=TOP, anchor=W, padx=15, pady=5) # frame_save. frame_save.pack(side=TOP, padx=5, pady=0, fill=X) run_save_title.pack(side=LEFT, anchor=W, padx=5, pady=5) self.save_auto_on.pack(side=RIGHT, anchor=W, padx=5, pady=5) self.save_ask_on.pack(side=RIGHT, anchor=W, padx=5, pady=5) # frame_format. frame_format.pack(side=TOP, padx=5, pady=0, fill=X) format_width_title.pack(side=LEFT, anchor=W, padx=5, pady=5) self.format_width_int.pack(side=TOP, padx=10, pady=5) # frame_line_numbers_default. frame_line_numbers_default.pack(side=TOP, padx=5, pady=0, fill=X) line_numbers_default_title.pack(side=LEFT, anchor=W, padx=5, pady=5) self.line_numbers_default_bool.pack(side=LEFT, padx=5, pady=5) # frame_context. frame_context.pack(side=TOP, padx=5, pady=0, fill=X) context_title.pack(side=LEFT, anchor=W, padx=5, pady=5) self.context_int.pack(side=TOP, padx=5, pady=5) # frame_auto_squeeze_min_lines frame_auto_squeeze_min_lines.pack(side=TOP, padx=5, pady=0, fill=X) auto_squeeze_min_lines_title.pack(side=LEFT, anchor=W, padx=5, pady=5) self.auto_squeeze_min_lines_int.pack(side=TOP, padx=5, pady=5) # frame_help. frame_helplist_buttons.pack(side=RIGHT, padx=5, pady=5, fill=Y) frame_helplist.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) scroll_helplist.pack(side=RIGHT, anchor=W, fill=Y) self.helplist.pack(side=LEFT, anchor=E, expand=TRUE, fill=BOTH) self.button_helplist_edit.pack(side=TOP, anchor=W, pady=5) self.button_helplist_add.pack(side=TOP, anchor=W) self.button_helplist_remove.pack(side=TOP, anchor=W, pady=5)
Return frame of widgets for General tab. Enable users to provisionally change general options. Function load_general_cfg initializes tk variables and helplist using idleConf. Radiobuttons startup_shell_on and startup_editor_on set var startup_edit. Radiobuttons save_ask_on and save_auto_on set var autosave. Entry boxes win_width_int and win_height_int set var win_width and win_height. Setting var_name invokes the default callback that adds option to changes. Helplist: load_general_cfg loads list user_helplist with name, position pairs and copies names to listbox helplist. Clicking a name invokes help_source selected. Clicking button_helplist_name invokes helplist_item_name, which also changes user_helplist. These functions all call set_add_delete_state. All but load call update_help_changes to rewrite changes['main']['HelpFiles']. Widgets for GenPage(Frame): (*) widgets bound to self frame_window: LabelFrame frame_run: Frame startup_title: Label (*)startup_editor_on: Radiobutton - startup_edit (*)startup_shell_on: Radiobutton - startup_edit frame_win_size: Frame win_size_title: Label win_width_title: Label (*)win_width_int: Entry - win_width win_height_title: Label (*)win_height_int: Entry - win_height frame_cursor_blink: Frame cursor_blink_title: Label (*)cursor_blink_bool: Checkbutton - cursor_blink frame_autocomplete: Frame auto_wait_title: Label (*)auto_wait_int: Entry - autocomplete_wait frame_paren1: Frame paren_style_title: Label (*)paren_style_type: OptionMenu - paren_style frame_paren2: Frame paren_time_title: Label (*)paren_flash_time: Entry - flash_delay (*)bell_on: Checkbutton - paren_bell frame_editor: LabelFrame frame_save: Frame run_save_title: Label (*)save_ask_on: Radiobutton - autosave (*)save_auto_on: Radiobutton - autosave frame_format: Frame format_width_title: Label (*)format_width_int: Entry - format_width frame_line_numbers_default: Frame line_numbers_default_title: Label (*)line_numbers_default_bool: Checkbutton - line_numbers_default frame_context: Frame context_title: Label (*)context_int: Entry - context_lines frame_shell: LabelFrame frame_auto_squeeze_min_lines: Frame auto_squeeze_min_lines_title: Label (*)auto_squeeze_min_lines_int: Entry - auto_squeeze_min_lines frame_help: LabelFrame frame_helplist: Frame frame_helplist_buttons: Frame (*)button_helplist_edit (*)button_helplist_add (*)button_helplist_remove (*)helplist: ListBox scroll_helplist: Scrollbar
create_page_general
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def helplist_item_add(self): """Handle add button for the help list. Query for name and location of new help sources and add them to the list. """ help_source = HelpSource(self, 'New Help Source').result if help_source: self.user_helplist.append(help_source) self.helplist.insert(END, help_source[0]) self.update_help_changes()
Handle add button for the help list. Query for name and location of new help sources and add them to the list.
helplist_item_add
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def helplist_item_edit(self): """Handle edit button for the help list. Query with existing help source information and update config if the values are changed. """ item_index = self.helplist.index(ANCHOR) help_source = self.user_helplist[item_index] new_help_source = HelpSource( self, 'Edit Help Source', menuitem=help_source[0], filepath=help_source[1], ).result if new_help_source and new_help_source != help_source: self.user_helplist[item_index] = new_help_source self.helplist.delete(item_index) self.helplist.insert(item_index, new_help_source[0]) self.update_help_changes() self.set_add_delete_state() # Selected will be un-selected
Handle edit button for the help list. Query with existing help source information and update config if the values are changed.
helplist_item_edit
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def helplist_item_remove(self): """Handle remove button for the help list. Delete the help list item from config. """ item_index = self.helplist.index(ANCHOR) del(self.user_helplist[item_index]) self.helplist.delete(item_index) self.update_help_changes() self.set_add_delete_state()
Handle remove button for the help list. Delete the help list item from config.
helplist_item_remove
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def __init__(self): """Store Tk variables and callbacks. untraced: List of tuples (var, callback) that do not have the callback attached to the Tk var. traced: List of tuples (var, callback) where that callback has been attached to the var. """ self.untraced = [] self.traced = []
Store Tk variables and callbacks. untraced: List of tuples (var, callback) that do not have the callback attached to the Tk var. traced: List of tuples (var, callback) where that callback has been attached to the var.
__init__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def add(self, var, callback): """Add (var, callback) tuple to untraced list. Args: var: Tk variable instance. callback: Either function name to be used as a callback or a tuple with IdleConf config-type, section, and option names used in the default callback. Return: Tk variable instance. """ if isinstance(callback, tuple): callback = self.make_callback(var, callback) self.untraced.append((var, callback)) return var
Add (var, callback) tuple to untraced list. Args: var: Tk variable instance. callback: Either function name to be used as a callback or a tuple with IdleConf config-type, section, and option names used in the default callback. Return: Tk variable instance.
add
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/configdialog.py
MIT
def get_parser(self, index): """ Return a parser object with index at 'index' """ return HyperParser(self.editwin, index)
Return a parser object with index at 'index'
get_parser
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_hyperparser.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_hyperparser.py
MIT
def test_init(self): """ test corner cases in the init method """ with self.assertRaises(ValueError) as ve: self.text.tag_add('console', '1.0', '1.end') p = self.get_parser('1.5') self.assertIn('precedes', str(ve.exception)) # test without ps1 self.editwin.prompt_last_line = '' # number of lines lesser than 50 p = self.get_parser('end') self.assertEqual(p.rawtext, self.text.get('1.0', 'end')) # number of lines greater than 50 self.text.insert('end', self.text.get('1.0', 'end')*4) p = self.get_parser('54.5')
test corner cases in the init method
test_init
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_hyperparser.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_hyperparser.py
MIT
def stackorder(): """Get the stack order of the children of the frame. winfo_children() stores the children in stack order, so this can be used to check whether a frame is above or below another one. """ for index, child in enumerate(dialog.frame.winfo_children()): if child._name == 'keyseq_basic': basic = index if child._name == 'keyseq_advanced': advanced = index return basic, advanced
Get the stack order of the children of the frame. winfo_children() stores the children in stack order, so this can be used to check whether a frame is above or below another one.
test_toggle_level.stackorder
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_config_key.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_config_key.py
MIT
def test_toggle_level(self): dialog = self.dialog def stackorder(): """Get the stack order of the children of the frame. winfo_children() stores the children in stack order, so this can be used to check whether a frame is above or below another one. """ for index, child in enumerate(dialog.frame.winfo_children()): if child._name == 'keyseq_basic': basic = index if child._name == 'keyseq_advanced': advanced = index return basic, advanced # New window starts at basic level. self.assertFalse(dialog.advanced) self.assertIn('Advanced', dialog.button_level['text']) basic, advanced = stackorder() self.assertGreater(basic, advanced) # Toggle to advanced. dialog.toggle_level() self.assertTrue(dialog.advanced) self.assertIn('Basic', dialog.button_level['text']) basic, advanced = stackorder() self.assertGreater(advanced, basic) # Toggle to basic. dialog.button_level.invoke() self.assertFalse(dialog.advanced) self.assertIn('Advanced', dialog.button_level['text']) basic, advanced = stackorder() self.assertGreater(basic, advanced)
Get the stack order of the children of the frame. winfo_children() stores the children in stack order, so this can be used to check whether a frame is above or below another one.
test_toggle_level
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_config_key.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_config_key.py
MIT
def get_test_tk_root(test_instance): """Helper for tests: Create a root Tk object.""" requires('gui') root = Tk() root.withdraw() def cleanup_root(): root.update_idletasks() root.destroy() test_instance.addCleanup(cleanup_root) return root
Helper for tests: Create a root Tk object.
get_test_tk_root
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def test_count_empty(self): """Test with an empty string.""" self.assertEqual(count_lines_with_wrapping(""), 0)
Test with an empty string.
test_count_empty
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def test_count_begins_with_empty_line(self): """Test with a string which begins with a newline.""" self.assertEqual(count_lines_with_wrapping("\ntext"), 2)
Test with a string which begins with a newline.
test_count_begins_with_empty_line
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def test_count_ends_with_empty_line(self): """Test with a string which ends with a newline.""" self.assertEqual(count_lines_with_wrapping("text\n"), 1)
Test with a string which ends with a newline.
test_count_ends_with_empty_line
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def test_count_several_lines(self): """Test with several lines of text.""" self.assertEqual(count_lines_with_wrapping("1\n2\n3\n"), 3)
Test with several lines of text.
test_count_several_lines
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def make_mock_editor_window(self, with_text_widget=False): """Create a mock EditorWindow instance.""" editwin = NonCallableMagicMock() editwin.width = 80 if with_text_widget: editwin.root = get_test_tk_root(self) text_widget = self.make_text_widget(root=editwin.root) editwin.text = editwin.per.bottom = text_widget return editwin
Create a mock EditorWindow instance.
make_mock_editor_window
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def make_squeezer_instance(self, editor_window=None): """Create an actual Squeezer instance with a mock EditorWindow.""" if editor_window is None: editor_window = self.make_mock_editor_window() squeezer = Squeezer(editor_window) return squeezer
Create an actual Squeezer instance with a mock EditorWindow.
make_squeezer_instance
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def test_count_lines(self): """Test Squeezer.count_lines() with various inputs.""" editwin = self.make_mock_editor_window() squeezer = self.make_squeezer_instance(editwin) for text_code, line_width, expected in [ (r"'\n'", 80, 1), (r"'\n' * 3", 80, 3), (r"'a' * 40 + '\n'", 80, 1), (r"'a' * 80 + '\n'", 80, 1), (r"'a' * 200 + '\n'", 80, 3), (r"'aa\t' * 20", 80, 2), (r"'aa\t' * 21", 80, 3), (r"'aa\t' * 20", 40, 4), ]: with self.subTest(text_code=text_code, line_width=line_width, expected=expected): text = eval(text_code) with patch.object(editwin, 'width', line_width): self.assertEqual(squeezer.count_lines(text), expected)
Test Squeezer.count_lines() with various inputs.
test_count_lines
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def test_init(self): """Test the creation of Squeezer instances.""" editwin = self.make_mock_editor_window() squeezer = self.make_squeezer_instance(editwin) self.assertIs(squeezer.editwin, editwin) self.assertEqual(squeezer.expandingbuttons, [])
Test the creation of Squeezer instances.
test_init
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def test_write_no_tags(self): """Test Squeezer's overriding of the EditorWindow's write() method.""" editwin = self.make_mock_editor_window() for text in ['', 'TEXT', 'LONG TEXT' * 1000, 'MANY_LINES\n' * 100]: editwin.write = orig_write = Mock(return_value=SENTINEL_VALUE) squeezer = self.make_squeezer_instance(editwin) self.assertEqual(squeezer.editwin.write(text, ()), SENTINEL_VALUE) self.assertEqual(orig_write.call_count, 1) orig_write.assert_called_with(text, ()) self.assertEqual(len(squeezer.expandingbuttons), 0)
Test Squeezer's overriding of the EditorWindow's write() method.
test_write_no_tags
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def test_write_not_stdout(self): """Test Squeezer's overriding of the EditorWindow's write() method.""" for text in ['', 'TEXT', 'LONG TEXT' * 1000, 'MANY_LINES\n' * 100]: editwin = self.make_mock_editor_window() editwin.write.return_value = SENTINEL_VALUE orig_write = editwin.write squeezer = self.make_squeezer_instance(editwin) self.assertEqual(squeezer.editwin.write(text, "stderr"), SENTINEL_VALUE) self.assertEqual(orig_write.call_count, 1) orig_write.assert_called_with(text, "stderr") self.assertEqual(len(squeezer.expandingbuttons), 0)
Test Squeezer's overriding of the EditorWindow's write() method.
test_write_not_stdout
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def test_write_stdout(self): """Test Squeezer's overriding of the EditorWindow's write() method.""" editwin = self.make_mock_editor_window() for text in ['', 'TEXT']: editwin.write = orig_write = Mock(return_value=SENTINEL_VALUE) squeezer = self.make_squeezer_instance(editwin) squeezer.auto_squeeze_min_lines = 50 self.assertEqual(squeezer.editwin.write(text, "stdout"), SENTINEL_VALUE) self.assertEqual(orig_write.call_count, 1) orig_write.assert_called_with(text, "stdout") self.assertEqual(len(squeezer.expandingbuttons), 0) for text in ['LONG TEXT' * 1000, 'MANY_LINES\n' * 100]: editwin.write = orig_write = Mock(return_value=SENTINEL_VALUE) squeezer = self.make_squeezer_instance(editwin) squeezer.auto_squeeze_min_lines = 50 self.assertEqual(squeezer.editwin.write(text, "stdout"), None) self.assertEqual(orig_write.call_count, 0) self.assertEqual(len(squeezer.expandingbuttons), 1)
Test Squeezer's overriding of the EditorWindow's write() method.
test_write_stdout
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def test_auto_squeeze(self): """Test that the auto-squeezing creates an ExpandingButton properly.""" editwin = self.make_mock_editor_window(with_text_widget=True) text_widget = editwin.text squeezer = self.make_squeezer_instance(editwin) squeezer.auto_squeeze_min_lines = 5 squeezer.count_lines = Mock(return_value=6) editwin.write('TEXT\n'*6, "stdout") self.assertEqual(text_widget.get('1.0', 'end'), '\n') self.assertEqual(len(squeezer.expandingbuttons), 1)
Test that the auto-squeezing creates an ExpandingButton properly.
test_auto_squeeze
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def test_squeeze_current_text_event(self): """Test the squeeze_current_text event.""" # Squeezing text should work for both stdout and stderr. for tag_name in ["stdout", "stderr"]: editwin = self.make_mock_editor_window(with_text_widget=True) text_widget = editwin.text squeezer = self.make_squeezer_instance(editwin) squeezer.count_lines = Mock(return_value=6) # Prepare some text in the Text widget. text_widget.insert("1.0", "SOME\nTEXT\n", tag_name) text_widget.mark_set("insert", "1.0") self.assertEqual(text_widget.get('1.0', 'end'), 'SOME\nTEXT\n\n') self.assertEqual(len(squeezer.expandingbuttons), 0) # Test squeezing the current text. retval = squeezer.squeeze_current_text_event(event=Mock()) self.assertEqual(retval, "break") self.assertEqual(text_widget.get('1.0', 'end'), '\n\n') self.assertEqual(len(squeezer.expandingbuttons), 1) self.assertEqual(squeezer.expandingbuttons[0].s, 'SOME\nTEXT') # Test that expanding the squeezed text works and afterwards # the Text widget contains the original text. squeezer.expandingbuttons[0].expand(event=Mock()) self.assertEqual(text_widget.get('1.0', 'end'), 'SOME\nTEXT\n\n') self.assertEqual(len(squeezer.expandingbuttons), 0)
Test the squeeze_current_text event.
test_squeeze_current_text_event
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def test_squeeze_current_text_event_no_allowed_tags(self): """Test that the event doesn't squeeze text without a relevant tag.""" editwin = self.make_mock_editor_window(with_text_widget=True) text_widget = editwin.text squeezer = self.make_squeezer_instance(editwin) squeezer.count_lines = Mock(return_value=6) # Prepare some text in the Text widget. text_widget.insert("1.0", "SOME\nTEXT\n", "TAG") text_widget.mark_set("insert", "1.0") self.assertEqual(text_widget.get('1.0', 'end'), 'SOME\nTEXT\n\n') self.assertEqual(len(squeezer.expandingbuttons), 0) # Test squeezing the current text. retval = squeezer.squeeze_current_text_event(event=Mock()) self.assertEqual(retval, "break") self.assertEqual(text_widget.get('1.0', 'end'), 'SOME\nTEXT\n\n') self.assertEqual(len(squeezer.expandingbuttons), 0)
Test that the event doesn't squeeze text without a relevant tag.
test_squeeze_current_text_event_no_allowed_tags
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def test_squeeze_text_before_existing_squeezed_text(self): """Test squeezing text before existing squeezed text.""" editwin = self.make_mock_editor_window(with_text_widget=True) text_widget = editwin.text squeezer = self.make_squeezer_instance(editwin) squeezer.count_lines = Mock(return_value=6) # Prepare some text in the Text widget and squeeze it. text_widget.insert("1.0", "SOME\nTEXT\n", "stdout") text_widget.mark_set("insert", "1.0") squeezer.squeeze_current_text_event(event=Mock()) self.assertEqual(len(squeezer.expandingbuttons), 1) # Test squeezing the current text. text_widget.insert("1.0", "MORE\nSTUFF\n", "stdout") text_widget.mark_set("insert", "1.0") retval = squeezer.squeeze_current_text_event(event=Mock()) self.assertEqual(retval, "break") self.assertEqual(text_widget.get('1.0', 'end'), '\n\n\n') self.assertEqual(len(squeezer.expandingbuttons), 2) self.assertTrue(text_widget.compare( squeezer.expandingbuttons[0], '<', squeezer.expandingbuttons[1], ))
Test squeezing text before existing squeezed text.
test_squeeze_text_before_existing_squeezed_text
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def test_reload(self): """Test the reload() class-method.""" editwin = self.make_mock_editor_window(with_text_widget=True) squeezer = self.make_squeezer_instance(editwin) orig_auto_squeeze_min_lines = squeezer.auto_squeeze_min_lines # Increase auto-squeeze-min-lines. new_auto_squeeze_min_lines = orig_auto_squeeze_min_lines + 10 self.set_idleconf_option_with_cleanup( 'main', 'PyShell', 'auto-squeeze-min-lines', str(new_auto_squeeze_min_lines)) Squeezer.reload() self.assertEqual(squeezer.auto_squeeze_min_lines, new_auto_squeeze_min_lines)
Test the reload() class-method.
test_reload
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def test_reload_no_squeezer_instances(self): """Test that Squeezer.reload() runs without any instances existing.""" Squeezer.reload()
Test that Squeezer.reload() runs without any instances existing.
test_reload_no_squeezer_instances
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def make_mock_squeezer(self): """Helper for tests: Create a mock Squeezer object.""" root = get_test_tk_root(self) squeezer = Mock() squeezer.editwin.text = Text(root) # Set default values for the configuration settings. squeezer.auto_squeeze_min_lines = 50 return squeezer
Helper for tests: Create a mock Squeezer object.
make_mock_squeezer
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def test_init(self, MockHovertip): """Test the simplest creation of an ExpandingButton.""" squeezer = self.make_mock_squeezer() text_widget = squeezer.editwin.text expandingbutton = ExpandingButton('TEXT', 'TAGS', 50, squeezer) self.assertEqual(expandingbutton.s, 'TEXT') # Check that the underlying tkinter.Button is properly configured. self.assertEqual(expandingbutton.master, text_widget) self.assertTrue('50 lines' in expandingbutton.cget('text')) # Check that the text widget still contains no text. self.assertEqual(text_widget.get('1.0', 'end'), '\n') # Check that the mouse events are bound. self.assertIn('<Double-Button-1>', expandingbutton.bind()) right_button_code = '<Button-%s>' % ('2' if macosx.isAquaTk() else '3') self.assertIn(right_button_code, expandingbutton.bind()) # Check that ToolTip was called once, with appropriate values. self.assertEqual(MockHovertip.call_count, 1) MockHovertip.assert_called_with(expandingbutton, ANY, hover_delay=ANY) # Check that 'right-click' appears in the tooltip text. tooltip_text = MockHovertip.call_args[0][1] self.assertIn('right-click', tooltip_text.lower())
Test the simplest creation of an ExpandingButton.
test_init
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def test_expand(self): """Test the expand event.""" squeezer = self.make_mock_squeezer() expandingbutton = ExpandingButton('TEXT', 'TAGS', 50, squeezer) # Insert the button into the text widget # (this is normally done by the Squeezer class). text_widget = expandingbutton.text text_widget.window_create("1.0", window=expandingbutton) # Set base_text to the text widget, so that changes are actually # made to it (by ExpandingButton) and we can inspect these # changes afterwards. expandingbutton.base_text = expandingbutton.text # trigger the expand event retval = expandingbutton.expand(event=Mock()) self.assertEqual(retval, None) # Check that the text was inserted into the text widget. self.assertEqual(text_widget.get('1.0', 'end'), 'TEXT\n') # Check that the 'TAGS' tag was set on the inserted text. text_end_index = text_widget.index('end-1c') self.assertEqual(text_widget.get('1.0', text_end_index), 'TEXT') self.assertEqual(text_widget.tag_nextrange('TAGS', '1.0'), ('1.0', text_end_index)) # Check that the button removed itself from squeezer.expandingbuttons. self.assertEqual(squeezer.expandingbuttons.remove.call_count, 1) squeezer.expandingbuttons.remove.assert_called_with(expandingbutton)
Test the expand event.
test_expand
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT
def test_expand_dangerous_oupput(self): """Test that expanding very long output asks user for confirmation.""" squeezer = self.make_mock_squeezer() text = 'a' * 10**5 expandingbutton = ExpandingButton(text, 'TAGS', 50, squeezer) expandingbutton.set_is_dangerous() self.assertTrue(expandingbutton.is_dangerous) # Insert the button into the text widget # (this is normally done by the Squeezer class). text_widget = expandingbutton.text text_widget.window_create("1.0", window=expandingbutton) # Set base_text to the text widget, so that changes are actually # made to it (by ExpandingButton) and we can inspect these # changes afterwards. expandingbutton.base_text = expandingbutton.text # Patch the message box module to always return False. with patch('idlelib.squeezer.tkMessageBox') as mock_msgbox: mock_msgbox.askokcancel.return_value = False mock_msgbox.askyesno.return_value = False # Trigger the expand event. retval = expandingbutton.expand(event=Mock()) # Check that the event chain was broken and no text was inserted. self.assertEqual(retval, 'break') self.assertEqual(expandingbutton.text.get('1.0', 'end-1c'), '') # Patch the message box module to always return True. with patch('idlelib.squeezer.tkMessageBox') as mock_msgbox: mock_msgbox.askokcancel.return_value = True mock_msgbox.askyesno.return_value = True # Trigger the expand event. retval = expandingbutton.expand(event=Mock()) # Check that the event chain wasn't broken and the text was inserted. self.assertEqual(retval, None) self.assertEqual(expandingbutton.text.get('1.0', 'end-1c'), text)
Test that expanding very long output asks user for confirmation.
test_expand_dangerous_oupput
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/idlelib/idle_test/test_squeezer.py
MIT