rem stringlengths 0 322k | add stringlengths 0 2.05M | context stringlengths 8 228k |
|---|---|---|
print qemu_cmd | sys.stderr.write( qemu_cmd) | def launch_qemu(): img_name = "../sadbox/test.img" qemu_port = 5555 qemu_cmd = construct_qemu_shell_cmd(img_name, qemu_port) print qemu_cmd qemu_args = shlex.split(qemu_cmd) print "spinning up qemu instance" qemu_process = subprocess.Popen(qemu_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True) time.s... |
print "spinning up qemu instance" | sys.stderr.write( "spinning up qemu instance") | def launch_qemu(): img_name = "../sadbox/test.img" qemu_port = 5555 qemu_cmd = construct_qemu_shell_cmd(img_name, qemu_port) print qemu_cmd qemu_args = shlex.split(qemu_cmd) print "spinning up qemu instance" qemu_process = subprocess.Popen(qemu_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True) time.s... |
print "Error starting qemu instance, max retries exceeded" | sys.stderr.write( "Error starting qemu instance, max retries exceeded") | def launch_qemu(): img_name = "../sadbox/test.img" qemu_port = 5555 qemu_cmd = construct_qemu_shell_cmd(img_name, qemu_port) print qemu_cmd qemu_args = shlex.split(qemu_cmd) print "spinning up qemu instance" qemu_process = subprocess.Popen(qemu_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True) time.s... |
print str(err) | sys.stderr.write( str(err)) | def main(): qemu_identfile = "../sadbox/sshkey/vmkey" dest_path = "contestvm@localhost:~" try: opts, args = getopt.getopt(sys.argv[1:], "d:c:", ["directory=", "command="]) except getopt.GetoptError, err: print str(err) usage() sys.exit(2) sadbox_path = None cmd = None for o, a in opts: if o in ("-d", "--directory"): sa... |
print sadbox_path, sadbox_dir, cmd | def main(): qemu_identfile = "../sadbox/sshkey/vmkey" dest_path = "contestvm@localhost:~" try: opts, args = getopt.getopt(sys.argv[1:], "d:c:", ["directory=", "command="]) except getopt.GetoptError, err: print str(err) usage() sys.exit(2) sadbox_path = None cmd = None for o, a in opts: if o in ("-d", "--directory"): sa... | |
print "executing command inside VM" | sys.stderr.write( "executing command inside VM") | def main(): qemu_identfile = "../sadbox/sshkey/vmkey" dest_path = "contestvm@localhost:~" try: opts, args = getopt.getopt(sys.argv[1:], "d:c:", ["directory=", "command="]) except getopt.GetoptError, err: print str(err) usage() sys.exit(2) sadbox_path = None cmd = None for o, a in opts: if o in ("-d", "--directory"): sa... |
def do_turn(pw): my_strongest = -1 their_weakest = 99999999 for x in range (0, len(pw.planets)): planet = pw.planets[x] if planet.owner == 1 and planet.num_ships > my_strongest: my_strongest = x elif planet.owner != 1 and planet.num_ships < their_weakest: their_weakest = x | class StringUtils: @staticmethod def input(): string = stdin.readline() return string | def do_turn(pw): my_strongest = -1 their_weakest = 99999999 for x in range (0, len(pw.planets)): planet = pw.planets[x] if planet.owner == 1 and planet.num_ships > my_strongest: my_strongest = x elif planet.owner != 1 and planet.num_ships < their_weakest: their_weakest = x if my_strongest != -1 and their_weakest != 99... |
if my_strongest != -1 and their_weakest != 99999999: pw.issue_order(my_strongest, their_weakest, pw.planets[my_strongest].num_ships / 2) pw.end_turn() | @staticmethod def output(string): stdout.write(string + "\n") stdout.flush() | def do_turn(pw): my_strongest = -1 their_weakest = 99999999 for x in range (0, len(pw.planets)): planet = pw.planets[x] if planet.owner == 1 and planet.num_ships > my_strongest: my_strongest = x elif planet.owner != 1 and planet.num_ships < their_weakest: their_weakest = x if my_strongest != -1 and their_weakest != 99... |
def main(): map_data = "" while True: line = StringUtils.input() if line[0:2] == "go": do_turn(PlanetWars(map_data)) map_data = "" else: map_data += line | class Fleet: """ Object representing an active fleet of ships. """ _instances = ['owner', 'num_ships', 'source_planet', 'destination_planet', 'total_trip_length', 'turns_remaining'] | def main(): map_data = "" while True: line = StringUtils.input() if line[0:2] == "go": do_turn(PlanetWars(map_data)) map_data = "" else: map_data += line |
if __name__ == "__main__": main() | def __init__(self, **kwds): for name in self._instances: setattr(self, name, kwds[name]) def remove_ships(self, amount): """ Removes given amount ships from the fleet object. """ self.num_ships -= (amount <= self.num_ships) and amount or self.num_ships def time_step(self): """ Decrements the number of turns by 1, not... | def main(): map_data = "" while True: line = StringUtils.input() if line[0:2] == "go": do_turn(PlanetWars(map_data)) map_data = "" else: map_data += line |
planets.append(make_planet(0, 0, 0, 5, 16)) | planets.append(make_planet(0, 0, 0, random.randint(0, 5), random.randint(1, 150))) | def fix_coordinates(planets): min_x, min_y = min_coords(planets) translate_planets(planets, -min_x, -min_y) |
return sub['timestamp'] - timedelta(year=1) | return sub['timestamp'] - timedelta(days=365) | def sort_key(sub): if sub['last_game_timestamp'] is not None: return sub['last_game_timestamp'] return sub['timestamp'] - timedelta(year=1) |
handler = logging.handlers.RotatingFileHandler("matchup.log", | try: handler = logging.handlers.RotatingFileHandler("matchup.log", | def main(): start_time = time.time() handler = logging.handlers.RotatingFileHandler("matchup.log", maxBytes=1000000, backupCount=5) logger.addHandler(handler) connection = MySQLdb.connect(host = server_info["db_host"], user = server_info["db_username"], passwd = server_info["db_password"], db = server_info["db_name"]) ... |
logger.addHandler(handler) | logger.addHandler(handler) except IOError: pass | def main(): start_time = time.time() handler = logging.handlers.RotatingFileHandler("matchup.log", maxBytes=1000000, backupCount=5) logger.addHandler(handler) connection = MySQLdb.connect(host = server_info["db_host"], user = server_info["db_username"], passwd = server_info["db_password"], db = server_info["db_name"]) ... |
p["x"] += maxRadius+2 p["y"] += maxRadius+2 | p["x"] += maxRadius p["y"] += maxRadius | def translate_planets(planets): for p in planets: p["x"] += maxRadius+2 p["y"] += maxRadius+2 |
planet_max = min(100, 5 * distance(p1, p2) - 1) | planet_max = min(100, 5 * distance(planets[1], planets[2]) - 1) | def not_valids(p1): for p in planets: adist = actual_distance(p, p1) if distance(p, p1) < minDistance or abs(adist-round(adist)) < epsilon: return True return False |
self.pack_start(self.details) | self.pack_start(self.details, False) | def __init__(self, scg, numeric_id, indicator_lookup): Tab.__init__(self, scg, numeric_id, indicator_lookup) self.scg = scg self.show_indicator("clear") self.tab_type = "streamer" set_tip = self.scg.parent.tooltips.set_tip self.encoder = "off" # can also be set to "mp3" or "ogg" depending on what i... |
scrolled = gtk.ScrolledWindow() self.details.add(scrolled) scrolled.show() scrolled.set_size_request(-1, 355) | self.scrolled_window = scrolled = gtk.ScrolledWindow() self.pack_start(scrolled, True) scrolled.set_size_request(-1, 100) | def __init__(self, scg, numeric_id, indicator_lookup): Tab.__init__(self, scg, numeric_id, indicator_lookup) self.scg = scg self.show_indicator("clear") self.tab_type = "streamer" set_tip = self.scg.parent.tooltips.set_tip self.encoder = "off" # can also be set to "mp3" or "ogg" depending on what i... |
self.objects = { "connections" : (self.connection_pane, ("loader", "saver")), | self.objects = { "metadata" : (self.metadata, "text"), "sideline" : (self.sideline, "active"), "prekick" : (self.kick_before_start, "active"), "connections" : (self.connection_pane, ("loader", "saver")), | def __init__(self, scg, numeric_id, indicator_lookup): Tab.__init__(self, scg, numeric_id, indicator_lookup) self.scg = scg self.show_indicator("clear") self.tab_type = "streamer" set_tip = self.scg.parent.tooltips.set_tip self.encoder = "off" # can also be set to "mp3" or "ogg" depending on what i... |
widget.resize(int(self.win_x), int(self.win_y)) def cb_stream_details_expand(self, expander, param_spec, next_expander): | widget.resize(int(self.win_x), 1) def cb_stream_details_expand(self, expander, param_spec, next_expander, sw): if expander.get_expanded(): sw.show() else: sw.hide() | def cb_after_realize(self, widget): widget.resize(int(self.win_x), int(self.win_y)) |
self.window.resize((int(self.win_x)), 100) print "*********** shrink window *************" | self.window.resize((int(self.win_x)), 1) else: self.window.resize((int(self.win_x)), 1000) | def cb_stream_details_expand(self, expander, param_spec, next_expander): if expander.get_expanded() == next_expander.get_expanded(): if not expander.get_expanded(): self.window.resize((int(self.win_x)), 100) print "*********** shrink window *************" else: next_expander.set_expanded(expander.get_expanded()) |
tab.details.connect("notify::expanded", self.cb_stream_details_expand, next_tab.details) | tab.details.connect("notify::expanded", self.cb_stream_details_expand, next_tab.details, tab.scrolled_window) | def __init__(self, parent): self.parent = parent parent.server_window = self self.win_x = int_object(100) self.win_y = int_object(100) self.source_client_crash_count = 0 self.source_client_open() self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.parent.window_group.add_window(self.window) self.window.set_title(ln.outp... |
metabar = MetadataBar(self, num_encoders, "%s") vbox.pack_start(metabar, False, False, 0) metabar.show() | def __init__(self, parent): self.parent = parent parent.server_window = self self.win_x = int_object(100) self.win_y = int_object(100) self.source_client_crash_count = 0 self.source_client_open() self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.parent.window_group.add_window(self.window) self.window.set_title(ln.outp... | |
def cb_active(self, widget): sens = widget.get_active() for each in (self.vbox, self.meter): each.set_sensitive(sens) if not sens: self.open.set_active(False) | def check(self, label_text, wname, save=True): cb = gtk.CheckButton(label_text) cb.connect("toggled", self.sendnewstats, wname) cb.emit("toggled") cb.show() if save: self.booleandict[self.commandname + "_" + wname] = cb return cb | |
self.mode.emit("changed") | def __init__(self, approot, ui_name, commandname, index): self.approot = approot self.ui_name = ui_name self.meter = approot.mic_meters[int(ui_name) - 1] self.commandname = commandname self.index = index self.valuesdict = {} self.booleandict = {} self.textdict = {} gtk.Frame.__init__(self) set_tip = approot.tooltips.se... | |
player= self.owner.player_right if v>=0x40 else self.owner.player_left | if isd: if self.owner.player_left.treeview.is_focus(): player = self.owner.player_right else: player = self.owner.player_left else: player= self.owner.player_right if v>=0x40 else self.owner.player_left | def x_focus(self, n, v, isd): player= self.owner.player_right if v>=0x40 else self.owner.player_left player.treeview.grab_focus() |
self.source_combo.connect_after("changed", self.cb_source_combo) | self.source_combo.connect("changed", self.cb_source_combo) | def populate_stream_selector(self, text, tabs): self.streamtabs = tabs for index in range(len(tabs)): self.source_combo.append_text(" ".join((text, str(index + 1)))) self.source_combo.connect_after("changed", self.cb_source_combo) self.source_combo.set_active(0) |
path= self.on_get_path(rowref) path= model_sort.convert_child_path_to_path(path) area= tree.get_background_area(path, column0) tree.get_bin_window().invalidate_rect(area, False) | try: path= self.on_get_path(rowref) except ValueError: pass else: path= model_sort.convert_child_path_to_path(path) area= tree.get_background_area(path, column0) tree.get_bin_window().invalidate_rect(area, False) | def cb_highlights(self, tree, column0, model_sort): d= self.highlights if d: for rowref, (count, is_new) in d.items(): # Highlights counter is reduced. if count < 1: del d[rowref] else: d[rowref]= (count - 1, False) # Treeview area invalidation to trigger a redraw. if is_new or rowref not in d: path= self.on_get_path(r... |
self.highlights[binding]= 5 | self.highlights[binding]= (5, True) | def input(self, input, v): """Dispatch incoming input to all bindings associated with it """ # If a BindingEditor is open in learning mode, inform it of the input # instead of doing anything with it. # if self.learner is not None: self.learner.learn(input) return |
path = tv.get_path_at_pos(x, y - 23) | path = tv.get_path_at_pos(*tv.convert_widget_to_bin_window_coords(x, y)) | def on_tooltip_query(self, tv, x, y, kb_mode, tooltip): if (x, y) != self.tooltip_coords: self.tooltip_coords = (x, y) elif None not in (x, y): path = tv.get_path_at_pos(x, y - 23) if path is not None: row = tv.get_model()[path[0]] hbox = gtk.HBox() hbox.set_spacing(3) hbox.pack_start(gtk.image_new_from_pixbuf(row[3].c... |
gobject.timeout_add(100, self.highlights_decimator) | def on_realize(self, tree, column0, model_sort): source= gobject.timeout_add(100, self.cb_highlights, tree, column0, model_sort) tree.connect_object('destroy', gobject.source_remove, source) | def __init__(self, owner): gtk.GenericTreeModel.__init__(self) self.owner= owner self.bindings= owner.owner.bindings self.highlights= owner.owner.highlights gobject.timeout_add(100, self.highlights_decimator) |
def highlights_decimator(self): | def cb_highlights(self, tree, column0, model_sort): | def highlights_decimator(self): d= self.highlights if d: for key, val in d.items(): if val > 1: d[key] -= 1 else: del d[key] win = self.owner.tree.get_bin_window() if win is not None: win.invalidate_rect(gtk.gdk.Rectangle(0, 0, 32768, 32768), False) return True |
for key, val in d.items(): if val > 1: d[key] -= 1 | for rowref, (count, is_new) in d.items(): if count < 1: del d[rowref] | def highlights_decimator(self): d= self.highlights if d: for key, val in d.items(): if val > 1: d[key] -= 1 else: del d[key] win = self.owner.tree.get_bin_window() if win is not None: win.invalidate_rect(gtk.gdk.Rectangle(0, 0, 32768, 32768), False) return True |
del d[key] win = self.owner.tree.get_bin_window() if win is not None: win.invalidate_rect(gtk.gdk.Rectangle(0, 0, 32768, 32768), False) | d[rowref]= (count - 1, False) if is_new or rowref not in d: path= self.on_get_path(rowref) path= model_sort.convert_child_path_to_path(path) area= tree.get_background_area(path, column0) tree.get_bin_window().invalidate_rect(area, False) | def highlights_decimator(self): d= self.highlights if d: for key, val in d.items(): if val > 1: d[key] -= 1 else: del d[key] win = self.owner.tree.get_bin_window() if win is not None: win.invalidate_rect(gtk.gdk.Rectangle(0, 0, 32768, 32768), False) return True |
cuesheet = CueSheetListStore() | cuesheet = None | def get_media_metadata(self, filename): artist = u"" title = u"" length = 0 artist_retval = u"" title_retval = u"" # Strip away any file:// prefix if filename.count("file://", 0, 7): filename = filename[7:] elif filename.count("file:", 0, 5): filename = filename[5:] filext = supported.check_media(filename) if filext ... |
if text[start] == "i": | t = text[start] if t == "i": | def pl_unpack(self, text): # converts a string encoded list to a python list start = 0 item = 0 reply = [] while text[start] != "\n": end = start while text[end] != ":": end = end + 1 nextstart = int(text[start + 1 : end]) + end + 1 value = text[end + 1 : nextstart] try: if text[start] == "i": value = int(va... |
elif text[start] == "f": | elif t == "f": | def pl_unpack(self, text): # converts a string encoded list to a python list start = 0 item = 0 reply = [] while text[start] != "\n": end = start while text[end] != ":": end = end + 1 nextstart = int(text[start + 1 : end]) + end + 1 value = text[end + 1 : nextstart] try: if text[start] == "i": value = int(va... |
elif text[start] == "s": | elif t == "s": | def pl_unpack(self, text): # converts a string encoded list to a python list start = 0 item = 0 reply = [] while text[start] != "\n": end = start while text[end] != ":": end = end + 1 nextstart = int(text[start + 1 : end]) + end + 1 value = text[end + 1 : nextstart] try: if text[start] == "i": value = int(va... |
elif text[start] == "c": | elif t == "c": | def pl_unpack(self, text): # converts a string encoded list to a python list start = 0 item = 0 reply = [] while text[start] != "\n": end = start while text[end] != ":": end = end + 1 nextstart = int(text[start + 1 : end]) + end + 1 value = text[end + 1 : nextstart] try: if text[start] == "i": value = int(va... |
random_pathnames = [PlayerRow(*x).filename for x in random.sample(self.liststore, poolsize)] | def invoke_end_of_track_policy(self): # This is where we implement the playlist modes. mode_text = self.pl_mode.get_active_text() if self.is_playing == False: print "Assertion failed in: invoke_end_of_track_policy" return if mode_text == ln.manual: # For Manual mode just stop the player at the end of the track. print ... | |
timestamped_pathnames = [(fp.get(pn, 0), pn) for pn in random_pathnames] | timestamped_pathnames = [] while not timestamped_pathnames: random_pathnames = [PlayerRow(*x).filename for x in random.sample(self.liststore, poolsize)] timestamped_pathnames = [(fp.get(pn, 0), pn) for pn in random_pathnames if pn] | def invoke_end_of_track_policy(self): # This is where we implement the playlist modes. mode_text = self.pl_mode.get_active_text() if self.is_playing == False: print "Assertion failed in: invoke_end_of_track_policy" return if mode_text == ln.manual: # For Manual mode just stop the player at the end of the track. print ... |
self.volume = self.parent.deckadj.get_value() | self.volume1 = self.parent.deckadj.get_value() self.volume2 = self.parent.deck2adj.get_value() | def start_player(self, mute_f): self.nomute = not self.parent.mic_opener.any_mic_selected and self.parent.mixermode == self.parent.PRIVATE_PHONE if self.entry.get_text() == "": selection = self.treeview.get_selection() model, iter = selection.get_selected() if iter != None: self.entry.set_text(str(model.get_value(iter,... |
self.interadj.set_value(100.0) self.parent.deckadj.set_value(100.0) self.parent.deck2adj.set_value(100.0) | self.interadj.set_value(0.0) self.parent.deckadj.set_value(0.0) self.parent.deck2adj.set_value(0.0) | def start_player(self, mute_f): self.nomute = not self.parent.mic_opener.any_mic_selected and self.parent.mixermode == self.parent.PRIVATE_PHONE if self.entry.get_text() == "": selection = self.treeview.get_selection() model, iter = selection.get_selected() if iter != None: self.entry.set_text(str(model.get_value(iter,... |
self.parent.deckadj.set_value(30.0) self.parent.deck2adj.set_value(30.0) | if self.parent.prefs_window.dual_volume.get_active(): highest = max((self.volume1, self.volume2)) else: highest = self.volume2 = self.volume1 delta = min((self.NORMAL - highest, 0)) self.parent.deckadj.set_value(self.volume1 + delta) self.parent.deck2adj.set_value(self.volume2 + delta) | def start_player(self, mute_f): self.nomute = not self.parent.mic_opener.any_mic_selected and self.parent.mixermode == self.parent.PRIVATE_PHONE if self.entry.get_text() == "": selection = self.treeview.get_selection() model, iter = selection.get_selected() if iter != None: self.entry.set_text(str(model.get_value(iter,... |
self.parent.deckadj.set_value(self.volume) self.parent.deck2adj.set_value(self.volume) | v1 = self.parent.deckadj.get_value() v2 = self.parent.deck2adj.get_value() if max((v1, v2)) <= self.NORMAL: self.parent.deckadj.set_value(self.volume1) self.parent.deck2adj.set_value(self.volume2) | def stop_player(self, flush = True): if self.playing: self.playing = False self.entry.set_sensitive(True) print "Stop player" if flush == True: print "stop with flush" self.parent.mixer_write("ACTN=stopjingles\nend\n", True) else: print "stop without flush" self.stop.clicked() # this will take care of resetting the pla... |
elif result: | else: | def select(self, xpath): try: result = self.xpathev(xpath) except etree.XPathError: raise ValueError("Invalid XPath: %s" % xpath) if hasattr(result, '__iter__'): result = [self.__class__(root=x, expr=xpath, namespaces=self.namespaces) \ for x in result] elif result: result = [self.__class__(root=result, expr=xpath, nam... |
editor.buffer.select_range(*get_smart_select(editor)) | start, end = get_smart_select(editor) editor.buffer.select_range(end, start) | def smart_select(editor): from smart_select import get_smart_select editor.buffer.select_range(*get_smart_select(editor)) |
self.close() | self.request_close.emit() | def open_file(self, filename): editor = self.request_to_open_file.emit(filename) if not self.buffer.get_modified() and self.text == u'': self.close() return editor |
def get_matches(iter, ctx): | def get_match(iter, ctx): | def get_matches(iter, ctx): names = snippets_match_hash.get(ctx, {}) if not names: return [] matches = [] for cnt in sorted(names, reverse=True): end = iter.copy() end.backward_chars(cnt) match = end.get_slice(iter) if match in names[cnt]: matches.append(match) return matches |
return [] matches = [] | return None | def get_matches(iter, ctx): names = snippets_match_hash.get(ctx, {}) if not names: return [] matches = [] for cnt in sorted(names, reverse=True): end = iter.copy() end.backward_chars(cnt) match = end.get_slice(iter) if match in names[cnt]: matches.append(match) return matches |
matches.append(match) return matches | return match return None | def get_matches(iter, ctx): names = snippets_match_hash.get(ctx, {}) if not names: return [] matches = [] for cnt in sorted(names, reverse=True): end = iter.copy() end.backward_chars(cnt) match = end.get_slice(iter) if match in names[cnt]: matches.append(match) return matches |
matches = [] | matches = {} | def on_view_key_press_event(view, event, contexts, editor_ref): if event.keyval == gtk.keysyms.Tab: buffer = view.get_buffer() cursor = get_iter_at_cursor(buffer) matches = [] for ctx in contexts: matches.extend(get_matches(cursor, ctx)) if matches: return expand_snippet(view, contexts, matches) if buffer in stop_ma... |
matches.extend(get_matches(cursor, ctx)) | match = get_match(cursor, ctx) if match: matches[ctx] = find_all_snippets(ctx, match) | def on_view_key_press_event(view, event, contexts, editor_ref): if event.keyval == gtk.keysyms.Tab: buffer = view.get_buffer() cursor = get_iter_at_cursor(buffer) matches = [] for ctx in contexts: matches.extend(get_matches(cursor, ctx)) if matches: return expand_snippet(view, contexts, matches) if buffer in stop_ma... |
return expand_snippet(view, contexts, matches) | return expand_snippet(view, matches) | def on_view_key_press_event(view, event, contexts, editor_ref): if event.keyval == gtk.keysyms.Tab: buffer = view.get_buffer() cursor = get_iter_at_cursor(buffer) matches = [] for ctx in contexts: matches.extend(get_matches(cursor, ctx)) if matches: return expand_snippet(view, contexts, matches) if buffer in stop_ma... |
def find_all_snippets(contexts, match): result = [] for ctx in contexts: result.extend(s for s in loaded_snippets[ctx].values() if s.snippet == match) return result def expand_snippet(view, contexts, matches): | def find_all_snippets(ctx, match): return [s for s in loaded_snippets[ctx].values() if s.snippet == match] def expand_snippet(view, matches): | def find_all_snippets(contexts, match): result = [] for ctx in contexts: result.extend(s for s in loaded_snippets[ctx].values() if s.snippet == match) return result |
snippets = find_all_snippets(contexts, matches[0]) | snippets = matches.values()[0] | def expand_snippet(view, contexts, matches): if not matches: return False elif len(matches) == 1: snippets = find_all_snippets(contexts, matches[0]) if not snippets: return False if len(snippets) == 1: insert_snippet(view, get_iter_at_cursor(view.get_buffer()), snippets[0]) return True show_proposals(view, get_iter_a... |
show_proposals(view, get_iter_at_cursor(view.get_buffer()), contexts) | show_proposals(view, get_iter_at_cursor(view.get_buffer()), matches.keys()) | def expand_snippet(view, contexts, matches): if not matches: return False elif len(matches) == 1: snippets = find_all_snippets(contexts, matches[0]) if not snippets: return False if len(snippets) == 1: insert_snippet(view, get_iter_at_cursor(view.get_buffer()), snippets[0]) return True show_proposals(view, get_iter_a... |
matches = get_matches(context.get_iter(), self.ctx) snippets = [s for s in loaded_snippets[self.ctx].values() if s.snippet in matches] | match = get_match(context.get_iter(), self.ctx) snippets = [s for s in loaded_snippets[self.ctx].values() if s.snippet == match] | def do_populate(self, context): matches = get_matches(context.get_iter(), self.ctx) |
return key.decode('utf-8') | return key.encode('utf-8') | def get_key(self, key): if isinstance(key, unicode): return key.decode('utf-8') else: return key |
to_str(prefs[tool]['langs'].split(','))): | to_str(prefs[tool]['langs']).split(',')): | def get_run_menu(prefs, editor): menu = gtk.Menu() menu.set_reserve_toggle_size(False) has_selection = editor.buffer.get_has_selection() any_items = False for tool in sorted(prefs): if prefs[tool]['stdin'] == 'selection' and not has_selection: continue if prefs[tool]['langs'].strip() and editor.lang not in map(str.s... |
self.set_editor_prefs(editor, editor.uri, editor.contexts) | self.set_editor_prefs(editor, editor.uri, editor.lang) | def on_editor_settings_changed(self, editor): self.set_editor_prefs(editor, editor.uri, editor.contexts) for e in self.editors: if e is not editor: idle(self.set_editor_prefs, e, e.uri, e.contexts) |
idle(self.set_editor_prefs, e, e.uri, e.contexts) | idle(self.set_editor_prefs, e, e.uri, e.lang) | def on_editor_settings_changed(self, editor): self.set_editor_prefs(editor, editor.uri, editor.contexts) for e in self.editors: if e is not editor: idle(self.set_editor_prefs, e, e.uri, e.contexts) |
return self.get_type(pyfunc.pycore, type_name).get_object() else: return None | pyname = self.get_type(pyfunc.pycore, type_name) if pyname: return pyname.get_object() return None | def get_function_param_type(self, pyfunc, name): scope_path = self.get_scope_path(pyfunc.get_scope()) type_name = self.find_type_for(scope_path, name) if type_name: return self.get_type(pyfunc.pycore, type_name).get_object() else: return None |
obj = module[name] else: obj = pycore.get_module(name) self.type_cache[type_name] = obj return obj | try: pyname = module[name] except exceptions.AttributeNotFoundError: pyname = None else: pyname = pycore.get_module(name) self.type_cache[type_name] = pyname return pyname | def get_type(self, pycore, type_name): try: return self.type_cache[type_name] except KeyError: pass module, sep, name = type_name.strip('()').rpartition('.') if module: module = pycore.get_module(module) obj = module[name] else: obj = pycore.get_module(name) self.type_cache[type_name] = obj return obj |
def run_file(editor): | def show_and_run(editor, lines): | def send_code(editor): runner = get_ipython_runner(editor) if not runner.visible(): runner.show() lines = get_selection_or_current_line(editor) runner.run_lines(lines) |
line = [ '%%run %s' % editor.uri ] runner.run_lines(line) | runner.run_lines(lines) def run_file(editor): lines = [ '%%run %s' % editor.uri ] show_and_run(editor, lines) def debug_file(editor): lines = [ '%%run -d %s' %editor.uri ] show_and_run(editor, lines) | def run_file(editor): runner = get_ipython_runner(editor) if not runner.visible(): runner.show() editor.popup_widget(runner.panel) line = [ '%%run %s' % editor.uri ] runner.run_lines(line) |
shutil.copymode(filename, tmpfilename) | try: shutil.copymode(filename, tmpfilename) except OSError: pass | def save_file(filename, data, encoding): tmpfilename = realpath(filename) + '.bak' try: f = open(tmpfilename, 'w') except IOError: dname = dirname(tmpfilename) if not exists(dname): os.makedirs(dname, mode=0755) f = open(tmpfilename, 'w') else: raise f.write(data.encode(encoding)) f.close() if exists(filename): shut... |
nstart, nend = iter.forward_search(name, gtk.TEXT_SEARCH_VISIBLE_ONLY) | result = iter.forward_search(name, gtk.TEXT_SEARCH_VISIBLE_ONLY) if result is None: break nstart, nend = result | def mark_problems(editor, problems): start, end = editor.buffer.get_bounds() if editor.buffer.get_tag_table().lookup('flakes'): editor.buffer.remove_tag_by_name('flakes', start, end) for line, name, message in problems: iter = editor.buffer.get_iter_at_line(line-1) while iter.get_line() == line - 1: nstart, nend = it... |
accel = accelerator_name(key, mod) try: desc = shortcuts.registered_shortcuts[name][1] except KeyError: continue | def fill_actions(self): self.actions_view.set_model(None) | |
accel = accelerator_name(key, mod) desc = shortcuts.registered_shortcuts[name][1] | def fill_actions(self): self.actions_view.set_model(None) | |
if matched_tags[0]: | if matched_tags[0] and buf.get_tag_table().lookup(matched_tags[0]): | def reset_tags(buf): if matched_tags[0]: start, end = buf.get_bounds() buf.remove_tag_by_name(matched_tags[0], start, end) matched_tags[0] = None |
nstart, nend = iter.forward_search(name, gtk.TEXT_SEARCH_VISIBLE_ONLY) editor.buffer.apply_tag(get_tag(editor), nstart, nend) | while iter.get_line() == line - 1: nstart, nend = iter.forward_search(name, gtk.TEXT_SEARCH_VISIBLE_ONLY) if nstart.starts_word() and nend.ends_word(): break iter = nend editor.buffer.apply_tag(get_tag(editor), nstart, nend) | def mark_problems(editor, problems): start, end = editor.buffer.get_bounds() if editor.buffer.get_tag_table().lookup('flakes'): editor.buffer.remove_tag_by_name('flakes', start, end) for line, name, message in problems: iter = editor.buffer.get_iter_at_line(line-1) nstart, nend = iter.forward_search(name, gtk.TEXT_SE... |
return data.decode(encoding) | return data.encode(encoding) | def to_str(data, encoding='utf-8'): if isinstance(data, unicode): return data.decode(encoding) return data |
match = ws_match.match(get_line_text(iter)) if match and len(match.group()) < min_indent: min_indent = len(match.group()) | if not line_is_empty(iter): match = ws_match.match(get_line_text(iter)) if match and len(match.group()) < min_indent: min_indent = len(match.group()) min_indent_text = match.group() if min_indent == 1000: min_indent = 0 | def comment_range(editor, traversor): ws_match = re.compile(r'[ \t]*') min_indent = 1000 for iter in traversor(): match = ws_match.match(get_line_text(iter)) if match and len(match.group()) < min_indent: min_indent = len(match.group()) editor.buffer.begin_user_action() for iter in traversor(): iter.forward_chars(min_i... |
iter.forward_chars(min_indent) | if line_is_empty(iter): line_end = iter.copy() line_end.forward_to_line_end() if iter.get_line() == line_end.get_line(): editor.buffer.delete(iter, line_end) editor.buffer.insert(iter, min_indent_text) else: iter.forward_chars(min_indent) | def comment_range(editor, traversor): ws_match = re.compile(r'[ \t]*') min_indent = 1000 for iter in traversor(): match = ws_match.match(get_line_text(iter)) if match and len(match.group()) < min_indent: min_indent = len(match.group()) editor.buffer.begin_user_action() for iter in traversor(): iter.forward_chars(min_i... |
if os.access(editor.uri, os.W_OK): | path = editor.uri if os.path.exists(editor.uri) else os.path.dirname(editor.uri) if os.access(path, os.W_OK): | def writable_handler(editor): """Return empty string if file is writeable else None. Useful for ``ro`` marks""" if os.access(editor.uri, os.W_OK): return '' return None |
return None | def writable_handler(editor): """Return empty string if file is writeable else None. Useful for ``ro`` marks""" if os.access(editor.uri, os.W_OK): return '' return None | |
proc = Popen(command_to_run, stdout=PIPE, stderr=PIPE, bufsize=1, stdin=PIPE if stdin else None, cwd=editor.project_root, env=env) on_finish = lambda: os.remove(filename) | proc = Popen(command_to_run, stdout=PIPE, stderr=PIPE, bufsize=1, close_fds=True, stdin=open(stdin_fname) if stdin else None, cwd=editor.project_root, env=env) def on_finish(): os.remove(filename) if stdin: os.remove(stdin_fname) | def run(editor, tool): import os.path from subprocess import Popen, PIPE import tempfile editor.message('Running ' + tool.title) fd, filename = tempfile.mkstemp() os.write(fd, tool.script) os.close(fd) stdin = get_stdin(editor, tool.input) command_to_run = ['/usr/bin/env', 'sh', filename] env = {} env.update(os.en... |
stdout, stderr = proc.communicate(stdin) | stdout, stderr = proc.communicate() | def run(editor, tool): import os.path from subprocess import Popen, PIPE import tempfile editor.message('Running ' + tool.title) fd, filename = tempfile.mkstemp() os.write(fd, tool.script) os.close(fd) stdin = get_stdin(editor, tool.input) command_to_run = ['/usr/bin/env', 'sh', filename] env = {} env.update(os.en... |
self.window.set_border_width(5) | def __init__(self): | |
glib.io_add_watch(proc.stdout, glib.IO_IN|glib.IO_ERR, consume_io, editor, console, proc, on_finish) glib.io_add_watch(proc.stderr, glib.IO_IN|glib.IO_ERR, consume_io, editor, console, proc, on_finish) | glib.io_add_watch(proc.stdout, glib.IO_IN|glib.IO_ERR|glib.IO_HUP, consume_io, editor, console, proc, on_finish) glib.io_add_watch(proc.stderr, glib.IO_IN|glib.IO_ERR|glib.IO_HUP, consume_io, editor, console, proc, on_finish) | def consume_output(editor, proc, on_finish): console = get_console_widget(editor) buf = console.view.get_buffer() buf.delete(*buf.get_bounds()) unblock_fd(proc.stdout) unblock_fd(proc.stderr) glib.io_add_watch(proc.stdout, glib.IO_IN|glib.IO_ERR, consume_io, editor, console, proc, on_finish) glib.io_add_watch(proc.stde... |
if prefs[tool]['langs'] and editor.lang not in map(str.strip, prefs[tool]['langs'].split(',')): | if prefs[tool]['langs'].strip() and editor.lang not in map(str.strip, to_str(prefs[tool]['langs'].split(','))): | def get_run_menu(prefs, editor): menu = gtk.Menu() menu.set_reserve_toggle_size(False) has_selection = editor.buffer.get_has_selection() any_items = False for tool in sorted(prefs): if prefs[tool]['stdin'] == 'selection' and not has_selection: continue if prefs[tool]['langs'] and editor.lang not in map(str.strip, pr... |
button.connect('activate', on_replace_activate, editor, widget) | button.connect('clicked', on_replace_activate, editor, widget) | def create_widget(editor): widget = gtk.HBox(False, 10) widget.set_border_width(3) label = gtk.Label() label.set_text('_Search:') label.set_use_underline(True) widget.pack_start(label, False) entry = gtk.Entry() widget.pack_start(entry, False) widget.entry = entry label.set_mnemonic_widget(entry) entry.connect('activ... |
button.connect('activate', on_replace_all_activate, editor, widget) | button.connect('clicked', on_replace_all_activate, editor, widget) | def create_widget(editor): widget = gtk.HBox(False, 10) widget.set_border_width(3) label = gtk.Label() label.set_text('_Search:') label.set_use_underline(True) widget.pack_start(label, False) entry = gtk.Entry() widget.pack_start(entry, False) widget.entry = entry label.set_mnemonic_widget(entry) entry.connect('activ... |
start, end = active_widgets[editor] | start, end = editor.buffer.get_bounds() | def on_replace_all_activate(button, editor, widget): if editor not in active_widgets: return search = active_widgets[editor].entry.get_text() ignore_case = active_widgets[editor].ignore_case.get_active() regex = active_widgets[editor].regex.get_active() replace = unicode(active_widgets[editor].replace_entry.get_text()... |
if f not in opened_files and os.path.isfile(f): | if f not in opened_files and (not os.path.exists(f) or os.path.isfile(f)): | def get_manager(): parser = OptionParser() parser.add_option('-s', '--session', dest='session', help="Open snaked with specified session") parser.add_option('-w', '--windowed', action="store_true", dest='windowed', default = False, help="Open separate editor window instead tab") options, args = parser.parse_args() imp... |
'Do now show hidden files' ) | 'Do not show hidden files' ) | def toggle_hidden(self): if self.search_entry.get_text(): self.editor().message('You are not in browse mode') return |
if os.path.exists(editor.uri): | if editor.uri and os.path.exists(editor.uri): | def editor_opened(editor): editor.connect('file-saved', on_file_saved) if os.path.exists(editor.uri): add_job(editor) |
fd.write('00005PING\n') | fd.write('%s%04d\n'%(fifo_start, len(args))) | def get_manager(): parser = OptionParser() parser.add_option('-s', '--session', dest='session', help="Open snaked with specified session", default='default') parser.add_option('', '--select-session', action="store_true", dest='select_session', help="Show dialog to select session at startup", default=False) options, ar... |
data = fd.read(sz) if data == 'PING\n': return file_injector(fd, flag) if data.startswith('FILE:'): fname = data[5:-1] if fname not in opened_files: manager.open(fname) opened_files.append(fname) | count = int(fd.read(sz)) for n in xrange(count): sz = int(fd.read(5)) data = fd.read(sz) if data.startswith('FILE:'): fname = data[5:-1] if fname not in opened_files: manager.open(fname) opened_files.append(fname) else: print "Unknown descriptor" | def file_injector(fd, flag): sz = int(fd.read(5)) data = fd.read(sz) if data == 'PING\n': # ignore PING command and reads next return file_injector(fd, flag) if data.startswith('FILE:'): fname = data[5:-1] if fname not in opened_files: # FIXME: this is unreliable, is there some list in manager ? manager.open(fname) ope... |
manager.add_shortcut('ipython', '<ctrl>i', 'IPython', 'Toggle IPython', show_ipython) manager.add_shortcut('run-current-code', '<ctrl>r', 'IPython', 'Send current line or selection in IPython', run_code) | manager.add_shortcut('ipython', '<ctrl>i', 'IPython', 'Toggle IPython console', show_ipython) manager.add_shortcut('run-current-code', '<ctrl>r', 'IPython', 'Send current line or selection to IPython', send_code) | def init(manager): manager.add_shortcut('ipython', '<ctrl>i', 'IPython', 'Toggle IPython', show_ipython) manager.add_shortcut('run-current-code', '<ctrl>r', 'IPython', 'Send current line or selection in IPython', run_code) manager.add_shortcut('run-code-file', 'F6', 'IPython', 'Run current file in IPython', run_file) m... |
def run_code(editor): | def send_code(editor): | def run_code(editor): runner = get_ipython_runner(editor) lines = get_selection_or_current_line(editor) runner.run_lines(lines) |
cpath = (None,) | cpath = () cpath_levels = (0,) | def get_outline(source): last_start = 0 last_line = 1 cpath = (None,) cname = None clevel = None for match in matcher.finditer(source): last_line = last_line + source.count('\n', last_start, match.start()) last_start = match.start() level, name = match.group('level', 'name') level = len(level) if clevel is None or le... |
clevel = None | def get_outline(source): last_start = 0 last_line = 1 cpath = (None,) cname = None clevel = None for match in matcher.finditer(source): last_line = last_line + source.count('\n', last_start, match.start()) last_start = match.start() level, name = match.group('level', 'name') level = len(level) if clevel is None or le... | |
if clevel is None or level < clevel: cpath = cpath[:-1] elif level > clevel: | if level < cpath_levels[-1]: while level < cpath_levels[-1]: cpath = cpath[:-1] cpath_levels = cpath_levels[:-1] elif level > cpath_levels[-1]: | def get_outline(source): last_start = 0 last_line = 1 cpath = (None,) cname = None clevel = None for match in matcher.finditer(source): last_line = last_line + source.count('\n', last_start, match.start()) last_start = match.start() level, name = match.group('level', 'name') level = len(level) if clevel is None or le... |
cpath_levels += (level, ) | def get_outline(source): last_start = 0 last_line = 1 cpath = (None,) cname = None clevel = None for match in matcher.finditer(source): last_line = last_line + source.count('\n', last_start, match.start()) last_start = match.start() level, name = match.group('level', 'name') level = len(level) if clevel is None or le... | |
clevel = level | def get_outline(source): last_start = 0 last_line = 1 cpath = (None,) cname = None clevel = None for match in matcher.finditer(source): last_line = last_line + source.count('\n', last_start, match.start()) last_start = match.start() level, name = match.group('level', 'name') level = len(level) if clevel is None or le... | |
roots = roots[:-2] + (self.outline.append(roots[-3], (name, '', line)),) | delta = len(ptop) - len(top) + 1 roots = roots[:-delta] + (self.outline.append(roots[-delta-1], (name, '', line)),) | def fill(self): self.outline.clear() current_search = object() self.current_search = current_search roots = (None, None) ptop = () i = 0 for top, name, line in get_outline(self.editor().text): if self.current_search is not current_search: return |
return self.snippet.snippet + (' ' + self.snippet.variant) if self.snippet.variant else '' | return self.snippet.snippet + ((' ' + self.snippet.variant) if self.snippet.variant else '') | def do_get_label(self): return self.snippet.snippet + (' ' + self.snippet.variant) if self.snippet.variant else '' |
return self.snippet.snippet + (' ' + self.snippet.variant) if self.snippet.variant else '' | return self.snippet.snippet + ((' ' + self.snippet.variant) if self.snippet.variant else '') | def do_get_text(self): return self.snippet.snippet + (' ' + self.snippet.variant) if self.snippet.variant else '' |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.