code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
from pyqode.core import panels, modes
self.modes.append(_LinkHighlighter(self.document()))
self.background = self._formatter.color_scheme.background
self.foreground = self._formatter.color_scheme.foreground
self._reset_stylesheet()
self.setCenterOnScroll(False)
... | def _init_code_edit(self, backend) | Initializes the code editor (setup modes, panels and colors). | 3.045883 | 2.993949 | 1.017346 |
environ = self._process.processEnvironment()
if env is None:
env = {}
for k, v in os.environ.items():
environ.insert(k, v)
for k, v in env.items():
environ.insert(k, v)
if sys.platform != 'win32':
environ.insert('TERM', 'xt... | def _setup_process_environment(self, env) | Sets up the process environment. | 2.767535 | 2.666286 | 1.037974 |
if self is None:
return
err = PROCESS_ERROR_STRING[error]
self._formatter.append_message(err + '\r\n', output_format=OutputFormat.ErrorMessageFormat) | def _on_process_error(self, error) | Display child process error in the text edit. | 14.60837 | 12.128402 | 1.204476 |
exit_code = self._process.exitCode()
if self._process.exitStatus() != self._process.NormalExit:
exit_code = 139
self._formatter.append_message('\x1b[0m\nProcess finished with exit code %d' % exit_code,
output_format=OutputFormat.CustomF... | def _on_process_finished(self) | Write the process finished message and emit the `finished` signal. | 5.814867 | 5.32812 | 1.091354 |
output = self._decode(self._process.readAllStandardOutput().data())
if self._formatter:
self._formatter.append_message(output, output_format=OutputFormat.NormalMessageFormat)
else:
self.insertPlainText(output) | def _read_stdout(self) | Reads the child process' stdout and process it. | 8.189346 | 7.622918 | 1.074306 |
output = self._decode(self._process.readAllStandardError().data())
if self._formatter:
self._formatter.append_message(output, output_format=OutputFormat.ErrorMessageFormat)
else:
self.insertPlainText(output) | def _read_stderr(self) | Reads the child process' stderr and process it. | 8.449162 | 7.919829 | 1.066836 |
self._prev_fmt = QtGui.QTextCharFormat(fmt)
self._prev_fmt_closed = False | def _set_format_scope(self, fmt) | Opens the format scope. | 8.632458 | 6.974941 | 1.237639 |
if event.key() == QtCore.Qt.Key_Return:
cursor = self.edit.textCursor()
cursor.movePosition(cursor.EndOfBlock)
self.edit.setTextCursor(cursor)
code = _qkey_to_ascii(event)
if code:
self.process.writeData(code)
return False
... | def key_press_event(self, event) | Directly writes the ascii code of the key to the process' stdin.
:retuns: False to prevent the event from being propagated to the parent widget. | 4.216041 | 3.824121 | 1.102486 |
try:
self._history.remove(command)
except ValueError:
pass
self._history.insert(0, command)
self._index = -1 | def add_command(self, command) | Adds a command to the history and reset history index. | 3.39204 | 2.60342 | 1.302917 |
self._index += 1
nb_commands = len(self._history)
if self._index >= nb_commands:
self._index = nb_commands - 1
try:
return self._history[self._index]
except IndexError:
return '' | def scroll_up(self) | Returns the previous command, if any. | 3.213962 | 2.491144 | 1.290155 |
self._index -= 1
if self._index < 0:
self._index = -1
return ''
try:
return self._history[self._index]
except IndexError:
return '' | def scroll_down(self) | Returns the next command if any. | 3.593202 | 2.870127 | 1.251931 |
self._clear_user_buffer()
tc = self.edit.textCursor()
tc.insertText(command)
self.edit.setTextCursor(tc) | def _insert_command(self, command) | Insert command by replacing the current input buffer and display it on the text edit. | 5.290511 | 3.757556 | 1.407966 |
input_buffer = self._get_input_buffer()
ctrl = int(event.modifiers() & QtCore.Qt.ControlModifier) != 0
shift = int(event.modifiers() & QtCore.Qt.ShiftModifier) != 0
delete = event.key() in [QtCore.Qt.Key_Backspace, QtCore.Qt.Key_Delete]
ignore = False
if delete a... | def key_press_event(self, event) | Manages our own buffer and send it to the subprocess when user pressed RETURN. | 2.409557 | 2.370351 | 1.01654 |
self._append_message(text, self._formats[output_format]) | def append_message(self, text, output_format=OutputFormat.NormalMessageFormat) | Parses and append message to the text edit. | 8.169229 | 6.062631 | 1.347472 |
self._cursor = self._text_edit.textCursor()
operations = self._parser.parse_text(FormattedText(text, char_format))
for i, operation in enumerate(operations):
try:
func = getattr(self, '_%s' % operation.command)
except AttributeError:
... | def _append_message(self, text, char_format) | Parses text and executes parsed operations. | 4.495153 | 3.859896 | 1.164579 |
theme = self._color_scheme
# normal message format
fmt = QtGui.QTextCharFormat()
fmt.setForeground(theme.foreground)
fmt.setBackground(theme.background)
self._formats[OutputFormat.NormalMessageFormat] = fmt
# error message
fmt = QtGui.QTextCharFo... | def _init_formats(self) | Initialise default formats. | 2.598392 | 2.509149 | 1.035567 |
self._cursor.clearSelection()
self._cursor.setPosition(self._last_cursor_pos)
if '\x07' in data.txt:
print('\a')
txt = data.txt.replace('\x07', '')
if '\x08' in txt:
parts = txt.split('\x08')
else:
parts = [txt]
for ... | def _draw(self, data) | Draw text | 3.311817 | 3.278135 | 1.010275 |
i = 0
while not self._cursor.atBlockEnd() and i < len(to_draw) and len(to_draw) > 1:
self._cursor.deleteChar()
i += 1
self._cursor.insertText(to_draw, data.fmt) | def _draw_chars(self, data, to_draw) | Draw the specified charachters using the specified format. | 4.875009 | 4.218714 | 1.155568 |
last_line = self._cursor.blockNumber() == self._text_edit.blockCount() - 1
if self._cursor.atEnd() or last_line:
if last_line:
self._cursor.movePosition(self._cursor.EndOfBlock)
self._cursor.insertText('\n')
else:
self._cursor.movePosi... | def _linefeed(self) | Performs a line feed. | 2.624984 | 2.631644 | 0.99747 |
self._cursor.clearSelection()
if self._cursor.atEnd():
self._cursor.insertText('\n')
else:
self._cursor.movePosition(self._cursor.Down, self._cursor.MoveAnchor, value)
self._last_cursor_pos = self._cursor.position() | def _cursor_down(self, value) | Moves the cursor down by ``value``. | 3.22938 | 3.26142 | 0.990176 |
value = int(value)
if value == 0:
value = 1
self._cursor.clearSelection()
self._cursor.movePosition(self._cursor.Up, self._cursor.MoveAnchor, value)
self._last_cursor_pos = self._cursor.position() | def _cursor_up(self, value) | Moves the cursor up by ``value``. | 3.088203 | 3.0573 | 1.010108 |
column, line = self._get_line_and_col(data)
self._move_cursor_to_line(line)
self._move_cursor_to_column(column)
self._last_cursor_pos = self._cursor.position() | def _cursor_position(self, data) | Moves the cursor position. | 3.612316 | 3.416924 | 1.057184 |
last_col = len(self._cursor.block().text())
self._cursor.movePosition(self._cursor.EndOfBlock)
to_insert = ''
for i in range(column - last_col):
to_insert += ' '
if to_insert:
self._cursor.insertText(to_insert)
self._cursor.movePosition(se... | def _move_cursor_to_column(self, column) | Moves the cursor to the specified column, if possible. | 2.523344 | 2.565959 | 0.983392 |
last_line = self._text_edit.document().blockCount() - 1
self._cursor.clearSelection()
self._cursor.movePosition(self._cursor.End)
to_insert = ''
for i in range(line - last_line):
to_insert += '\n'
if to_insert:
self._cursor.insertText(to_i... | def _move_cursor_to_line(self, line) | Moves the cursor to the specified line, if possible. | 2.335435 | 2.341837 | 0.997266 |
try:
line, column = data.split(';')
except AttributeError:
line = int(data)
column = 1
# handle empty values and convert them to 0 based indices
if not line:
line = 0
else:
line = int(line) - 1
if li... | def _get_line_and_col(data) | Gets line and column from a string like the following: "1;5" or "1;" or ";5"
and convers the column/line numbers to 0 base. | 2.595528 | 2.284675 | 1.13606 |
initial_pos = self._cursor.position()
if value == 0:
# delete end of line
self._cursor.movePosition(self._cursor.EndOfBlock, self._cursor.KeepAnchor)
elif value == 1:
# delete start of line
self._cursor.movePosition(self._cursor.StartOfBlo... | def _erase_in_line(self, value) | Erases charachters in line. | 2.116751 | 2.074814 | 1.020212 |
if value == 0:
# delete end of line
self._cursor.movePosition(self._cursor.End, self._cursor.KeepAnchor)
elif value == 1:
# delete start of line
self._cursor.movePosition(self._cursor.Start, self._cursor.KeepAnchor)
else:
# del... | def _erase_display(self, value) | Erases display. | 2.13142 | 2.108001 | 1.01111 |
if value <= 0:
value = 1
self._cursor.movePosition(self._cursor.Left, self._cursor.MoveAnchor, value)
self._text_edit.setTextCursor(self._cursor)
self._last_cursor_pos = self._cursor.position() | def _cursor_back(self, value) | Moves the cursor back. | 3.36258 | 3.246053 | 1.035898 |
if value <= 0:
value = 1
self._cursor.movePosition(self._cursor.Right, self._cursor.MoveAnchor, value)
self._text_edit.setTextCursor(self._cursor)
self._last_cursor_pos = self._cursor.position() | def _cursor_forward(self, value) | Moves the cursor forward. | 3.094061 | 3.088518 | 1.001795 |
value = int(value)
if value <= 0:
value = 1
for i in range(value):
self._cursor.deleteChar()
self._text_edit.setTextCursor(self._cursor)
self._last_cursor_pos = self._cursor.position() | def _delete_chars(self, value) | Deletes the specified number of charachters. | 3.498492 | 2.974357 | 1.176218 |
url = 'https://pypi.python.org/pypi/{}/json'.format(package)
r = requests.get(url)
r.raise_for_status()
return r.json() | def get_package_info(package) | Gets the PyPI information for a given package. | 2.032846 | 1.870569 | 1.086753 |
items = list(parse_requirements(req_file, session={}))
result = []
for item in items:
# Get line number from item
line_number = item.comes_from.split(req_file + ' (line ')[1][:-1]
if item.req:
item.req.marker = item.markers
result.append((item.req, line_... | def read_requirements(req_file) | Reads a requirements file.
Args:
req_file (str): Filename of requirements file | 4.159971 | 4.701368 | 0.884843 |
assert len(req.specifier) > 0
specs = list(req.specifier)
if len(specs) == 1:
# "foo > 2.0" or "foo == 2.4.3"
return specs[0].operator != '=='
else:
# "foo > 2.0, < 3.0"
return True | def _is_version_range(req) | Returns true if requirements specify a version range. | 3.918984 | 3.274993 | 1.196639 |
if not req.name:
return req, None
info = get_package_info(req.name)
if info['info'].get('_pypi_hidden'):
print('{} is hidden on PyPI and will not be updated.'.format(req))
return req, None
if _is_pinned(req) and _is_version_range(req):
print('{} is pinned to a ra... | def update_req(req) | Updates a given req object with the latest version. | 3.329416 | 3.224028 | 1.032688 |
with open(req_file, 'r') as input:
lines = input.readlines()
for req in reqs_linenum:
line_num = int(req[1])
if hasattr(req[0], 'link'):
lines[line_num - 1] = '{}\n'.format(req[0].link)
else:
lines[line_num - 1] = '{}\n'.format(req[0])
with ope... | def write_requirements(reqs_linenum, req_file) | Writes a list of req objects out to a given file. | 2.174976 | 2.135432 | 1.018518 |
if not isinstance(req, Requirement):
return None
info = get_package_info(req.name)
newest_version = _get_newest_version(info)
if _is_pinned(req) and _is_version_range(req):
return None
current_spec = next(iter(req.specifier)) if req.specifier else None
current_version = c... | def check_req(req) | Checks if a given req is the latest version available. | 3.433553 | 3.265185 | 1.051565 |
reqs = read_requirements(req_file)
if skip_packages is not None:
reqs = [req for req in reqs if req.name not in skip_packages]
outdated_reqs = filter(None, [check_req(req) for req in reqs])
return outdated_reqs | def check_requirements_file(req_file, skip_packages) | Return list of outdated requirements.
Args:
req_file (str): Filename of requirements file
skip_packages (list): List of package names to ignore. | 2.546886 | 2.72741 | 0.933811 |
updated = update_requirements_file(
args.requirements_file, args.skip_packages)
if updated:
print('Updated requirements in {}:'.format(args.requirements_file))
for item in updated:
print(' * {} from {} to {}.'.format(*item))
else:
print('All dependencies in... | def update_command(args) | Updates all dependencies the specified requirements file. | 3.859655 | 3.291604 | 1.172576 |
outdated = check_requirements_file(args.requirements_file,
args.skip_packages)
if outdated:
print('Requirements in {} are out of date:'.format(
args.requirements_file))
for item in outdated:
print(' * {} is {} latest is {}.'.f... | def check_command(args) | Checks that all dependencies in the specified requirements file are
up to date. | 4.031059 | 3.498228 | 1.152315 |
super(EncodingPanel, self).paintEvent(event)
if self.isVisible():
# fill background
painter = QtGui.QPainter(self)
self._background_brush = QtGui.QBrush(self._color)
painter.fillRect(event.rect(), self._background_brush) | def paintEvent(self, event) | Fills the panel background. | 3.39073 | 2.86448 | 1.183716 |
result = QtGui.QTextCharFormat()
items = list(style.style_for_token(token).items())
for key, value in items:
if value is None and key == 'color':
# make sure to use a default visible color for the foreground
# brush
value = dri... | def _get_format_from_style(self, token, style) | Returns a QTextCharFormat for token by reading a Pygments style. | 3.352063 | 3.170159 | 1.05738 |
color = str(color).replace("#", "")
qcolor = QtGui.QColor()
qcolor.setRgb(int(color[:2], base=16),
int(color[2:4], base=16),
int(color[4:6], base=16))
return qcolor | def _get_color(color) | Returns a QColor built from a Pygments color string. | 2.182325 | 1.823101 | 1.19704 |
self.editor.background = color_scheme.background
self.editor.foreground = color_scheme.formats[
'normal'].foreground().color()
self.editor.whitespaces_foreground = color_scheme.formats[
'whitespace'].foreground().color()
try:
mode = self.edito... | def refresh_editor(self, color_scheme) | Refresh editor settings (background and highlight colors) when color
scheme changed.
:param color_scheme: new color scheme. | 4.278649 | 4.416141 | 0.968866 |
start = time.time()
QtWidgets.QApplication.setOverrideCursor(
QtGui.QCursor(QtCore.Qt.WaitCursor))
try:
super(SyntaxHighlighter, self).rehighlight()
except RuntimeError:
# cloned widget, no need to rehighlight the same document twice ;)
... | def rehighlight(self) | Rehighlight the entire document, may be slow. | 4.210451 | 3.835721 | 1.097695 |
digits = 1
count = max(1, self.editor.blockCount())
while count >= 10:
count /= 10
digits += 1
space = 5 + self.editor.fontMetrics().width("9") * digits
return space | def line_number_area_width(self) | Computes the lineNumber area width depending on the number of lines
in the document
:return: Widtg | 4.358144 | 4.803048 | 0.907371 |
self._selecting = True
self._sel_start = e.pos().y()
start = end = TextHelper(self.editor).line_nbr_from_position(
self._sel_start)
self._start_line = start
TextHelper(self.editor).select_lines(start, end) | def mousePressEvent(self, e) | Starts selecting | 6.351999 | 5.864083 | 1.083204 |
try:
self._editor.cursorPositionChanged.disconnect(self.sync)
except (AttributeError, TypeError, RuntimeError, ReferenceError):
pass
try:
self._outline_mode.document_changed.disconnect(
self._on_changed)
except (AttributeError,... | def set_editor(self, editor) | Sets the current editor. The widget display the structure of that
editor.
:param editor: CodeEdit | 2.463905 | 2.641229 | 0.932863 |
self._updating = True
to_collapse = []
self.clear()
if self._editor and self._outline_mode and self._folding_panel:
items, to_collapse = self.to_tree_widget_items(
self._outline_mode.definitions, to_collapse=to_collapse)
if len(items):
... | def _on_changed(self) | Update the tree items | 4.455031 | 4.204777 | 1.059517 |
if item:
name = item.data(0, QtCore.Qt.UserRole)
if name:
go = name.block.blockNumber()
helper = TextHelper(self._editor)
if helper.current_line_nbr() != go:
helper.goto_line(go, column=name.column)
... | def _on_item_clicked(self, item) | Go to the item position in the editor. | 6.875294 | 5.700178 | 1.206154 |
def flatten(definitions):
ret_val = []
for de in definitions:
ret_val.append(de)
for sub_d in de.children:
ret_val.append(sub_d)
ret_val += flatten(sub_d.children)
return ret_val
... | def to_tree_widget_items(self, definitions, to_collapse=None) | Converts the list of top level definitions to a list of top level
tree items. | 2.524884 | 2.478732 | 1.018619 |
retval = None, None
original_cursor = self.editor.textCursor()
self.editor.setTextCursor(cursor)
block = cursor.block()
data = get_block_symbol_data(self.editor, block)
self._match(symbol_type, data, block.position())
for deco in self._decorations:
... | def symbol_pos(self, cursor, character_type=OPEN, symbol_type=PAREN) | Find the corresponding symbol position (line, column) of the specified
symbol. If symbol type is PAREN and character_type is OPEN, the
function will look for '('.
:param cursor: QTextCursor
:param character_type: character type to look for (open or close char)
:param symbol_type... | 4.262173 | 4.361031 | 0.977331 |
self._clear_decorations()
current_block = self.editor.textCursor().block()
data = get_block_symbol_data(self.editor, current_block)
pos = self.editor.textCursor().block().position()
for symbol in [PAREN, SQUARE, BRACE]:
self._match(symbol, data, pos) | def do_symbols_matching(self) | Performs symbols matching. | 5.83375 | 5.467141 | 1.067057 |
self.button.setVisible(visible)
left, top, right, bottom = self.getTextMargins()
if visible:
right = self._margin + self._spacing
else:
right = 0
self.setTextMargins(left, top, right, bottom) | def set_button_visible(self, visible) | Sets the clear button as ``visible``
:param visible: Visible state (True = visible, False = hidden). | 4.278331 | 5.112141 | 0.836896 |
path = klass.rfind(".")
class_name = klass[path + 1: len(klass)]
try:
module = __import__(klass[0:path], globals(), locals(), [class_name])
klass = getattr(module, class_name)
except ImportError as e:
raise ImportError('%s: %s' % (klass, str(e)))
except AttributeError:
... | def import_class(klass) | Imports a class from a fully qualified name string.
:param klass: class string, e.g.
"pyqode.core.backend.workers.CodeCompletionWorker"
:return: The corresponding class | 2.194452 | 2.320084 | 0.94585 |
class Unbuffered(object):
def __init__(self, stream):
self.stream = stream
def write(self, data):
self.stream.write(data)
self.stream.flush()
def __getattr__(self, attr):
return getattr(self.stream, attr)
sys.stdout = Unbuffered(sys... | def serve_forever(args=None) | Creates the server and serves forever
:param args: Optional args if you decided to use your own
argument parser. Default is None to let the JsonServer setup its own
parser and parse command line arguments. | 1.767045 | 1.659547 | 1.064776 |
self.action_to_lower = QtWidgets.QAction(self.editor)
self.action_to_lower.triggered.connect(self.to_lower)
self.action_to_upper = QtWidgets.QAction(self.editor)
self.action_to_upper.triggered.connect(self.to_upper)
self.action_to_lower.setText(_('Convert to lower case')... | def _create_actions(self) | Create associated actions | 1.841179 | 1.796082 | 1.025109 |
cursor = TextHelper(self.editor).word_under_mouse_cursor()
if (self._previous_cursor_start != cursor.selectionStart() and
self._previous_cursor_end != cursor.selectionEnd()):
self._remove_decoration()
self._add_decoration(cursor)
self._previous_cu... | def _select_word_cursor(self) | Selects the word under the mouse cursor. | 3.28388 | 3.000358 | 1.094496 |
if event.modifiers() & QtCore.Qt.ControlModifier:
cursor = TextHelper(self.editor).word_under_mouse_cursor()
if (not self._cursor or
cursor.position() != self._cursor.position()):
self._check_word_cursor(cursor)
self._cursor = curs... | def _on_mouse_moved(self, event) | mouse moved callback | 4.575721 | 4.484326 | 1.020381 |
if event.button() == 1 and self._deco:
cursor = TextHelper(self.editor).word_under_mouse_cursor()
if cursor and cursor.selectedText():
self._timer.request_job(
self.word_clicked.emit, cursor) | def _on_mouse_released(self, event) | mouse pressed callback | 14.92856 | 14.464132 | 1.032109 |
if self._deco is None:
if cursor.selectedText():
self._deco = TextDecoration(cursor)
if self.editor.background.lightness() < 128:
self._deco.set_foreground(QtGui.QColor('#0681e0'))
else:
self._deco.set_f... | def _add_decoration(self, cursor) | Adds a decoration for the word under ``cursor``. | 3.304093 | 3.111628 | 1.061853 |
if self._deco is not None:
self.editor.decorations.remove(self._deco)
self._deco = None | def _remove_decoration(self) | Removes the word under cursor's decoration | 4.457274 | 3.819483 | 1.166984 |
date = date.value
return (datetime.strptime(date[:-5], '%Y-%m-%dT%H:%M:%S')
if len(date) == 24
else datetime.strptime(date, '%Y%m%dT%H:%M:%S')) | def date(date) | DokuWiki returns dates of `xmlrpclib`/`xmlrpc.client` ``DateTime``
type and the format changes between DokuWiki versions ... This function
convert *date* to a `datetime` object. | 2.970454 | 2.903569 | 1.023036 |
date_offset = (datetime.now() - datetime.utcnow())
# Python < 2.7 don't have the 'total_seconds' method so calculate it by hand!
date_offset = (date_offset.microseconds +
(date_offset.seconds + date_offset.days * 24 * 3600) * 1e6) / 1e6
date_offset = int(round(date_offset / 60 / ... | def utc2local(date) | DokuWiki returns date with a +0000 timezone. This function convert *date*
to the local time. | 3.180024 | 3.110465 | 1.022363 |
try:
for header in response.msg.get_all("Set-Cookie"):
cookie = header.split(";", 1)[0]
cookieKey, cookieValue = cookie.split("=", 1)
self._cookies[cookieKey] = cookieValue
finally:
return Transport.parse_response(self, res... | def parse_response(self, response) | parse and store cookie | 3.846797 | 3.521372 | 1.092414 |
try:
for header in response.getheader("set-cookie").split(", "):
# filter 'expire' information
if not header.startswith("D"):
continue
cookie = header.split(";", 1)[0]
cookieKey, cookieValue = cookie.split("... | def parse_response(self, response) | parse and store cookie | 4.720038 | 4.425065 | 1.06666 |
args = list(args)
if kwargs:
args.append(kwargs)
method = self.proxy
for elt in command.split('.'):
method = getattr(method, elt)
try:
return method(*args)
except Fault as err:
if err.faultCode == 121:
... | def send(self, command, *args, **kwargs) | Generic method for executing an XML-RPC *command*. *args* and
*kwargs* are the arguments and parameters needed by the command. | 3.750122 | 3.445681 | 1.088355 |
return self.send('plugin.acl.addAcl', scope, user, permission) | def add_acl(self, scope, user, permission) | Add an `ACL <https://www.dokuwiki.org/acl>`_ rule that restricts
the page/namespace *scope* to *user* (use *@group* syntax for groups)
with *permission* level. It returns a boolean that indicate if the rule
was correctly added. | 11.45048 | 12.714714 | 0.900569 |
return (self._dokuwiki.send('wiki.getPageInfoVersion', page, version)
if version is not None
else self._dokuwiki.send('wiki.getPageInfo', page)) | def info(self, page, version=None) | Returns informations of *page*. Informations of the last version
is returned if *version* is not set. | 6.506743 | 6.242791 | 1.042281 |
return (self._dokuwiki.send('wiki.getPageVersion', page, version)
if version is not None
else self._dokuwiki.send('wiki.getPage', page)) | def get(self, page, version=None) | Returns the content of *page*. The content of the last version is
returned if *version* is not set. | 5.873258 | 6.160434 | 0.953384 |
return self._dokuwiki.send('dokuwiki.appendPage', page, content, options) | def append(self, page, content, **options) | Appends *content* text to *page*.
Valid *options* are:
* *sum*: (str) change summary
* *minor*: (bool) whether this is a minor change | 10.191696 | 19.189428 | 0.53111 |
return (self._dokuwiki.send('wiki.getPageHTMLVersion', page, version)
if version is not None
else self._dokuwiki.send('wiki.getPageHTML', page)) | def html(self, page, version=None) | Returns HTML content of *page*. The HTML content of the last version
of the page is returned if *version* is not set. | 6.302698 | 6.204838 | 1.015772 |
try:
return self._dokuwiki.send('wiki.putPage', page, content, options)
except ExpatError as err:
# Sometime the first line of the XML response is blank which raise
# the 'ExpatError' exception although the change has been done. This
# allow to ig... | def set(self, page, content, **options) | Set/replace the *content* of *page*.
Valid *options* are:
* *sum*: (str) change summary
* *minor*: (bool) whether this is a minor change | 10.635693 | 11.62342 | 0.915023 |
result = self._dokuwiki.send('dokuwiki.setLocks',
lock=[page], unlock=[])
if result['lockfail']:
raise DokuWikiError('unable to lock page') | def lock(self, page) | Locks *page*. | 12.90745 | 12.913082 | 0.999564 |
import os
data = self._dokuwiki.send('wiki.getAttachment', media)
data = base64.b64decode(data) if b64decode else data.data
if dirpath is None:
return data
if filename is None:
filename = media.replace('/', ':').split(':')[-1]
if not os.p... | def get(self, media, dirpath=None, filename=None, overwrite=False, b64decode=False) | Returns the binary data of *media* or save it to a file. If *dirpath*
is not set the binary data is returned, otherwise the data is saved
to a file. By default, the filename is the name of the media but it can
be changed with *filename* parameter. *overwrite* parameter allow to
overwrite... | 2.690363 | 2.603281 | 1.033451 |
with open(filepath, 'rb') as fhandler:
self._dokuwiki.send('wiki.putAttachment', media,
Binary(fhandler.read()), ow=overwrite) | def add(self, media, filepath, overwrite=True) | Set *media* from local file *filepath*. *overwrite* parameter specify
if the media must be overwrite if it exists remotely. | 14.519368 | 13.609043 | 1.066891 |
data = base64.b64encode(_bytes) if b64encode else Binary(_bytes)
self._dokuwiki.send('wiki.putAttachment', media, data, ow=overwrite) | def set(self, media, _bytes, overwrite=True, b64encode=False) | Set *media* from *_bytes*. *overwrite* parameter specify if the media
must be overwrite if it exists remotely. | 9.242259 | 8.872702 | 1.041651 |
if keep_order:
from collections import OrderedDict
dataentry = OrderedDict()
else:
dataentry = {}
found = False
for line in content.split('\n'):
if line.strip().startswith('---- dataentry'):
found = True
... | def get(content, keep_order=False) | Get dataentry from *content*. *keep_order* indicates whether to
return an ordered dictionnay. | 3.165055 | 2.918306 | 1.084552 |
return '---- dataentry %s ----\n%s\n----' % (name, '\n'.join(
'%s:%s' % (attr, value) for attr, value in data.items())) | def gen(name, data) | Generate dataentry *name* from *data*. | 6.33972 | 4.126705 | 1.536267 |
page_content = []
start = False
for line in content.split('\n'):
if line == '----' and not start:
start = True
continue
if start:
page_content.append(line)
return '\n'.join(page_content) if page_content else... | def ignore(content) | Remove dataentry from *content*. | 2.726067 | 2.805239 | 0.971777 |
checker_modes = []
for m in self.editor.modes:
if isinstance(m, modes.CheckerMode):
checker_modes.append(m)
for checker_mode in checker_modes:
for msg in checker_mode.messages:
block = msg.block
color = QtGui.QColor... | def _draw_messages(self, painter) | Draw messages from all subclass of CheckerMode currently
installed on the editor.
:type painter: QtGui.QPainter | 3.026623 | 2.799111 | 1.08128 |
if self.editor.visible_blocks:
start = self.editor.visible_blocks[0][-1]
end = self.editor.visible_blocks[-1][-1]
rect = QtCore.QRect()
rect.setX(0)
rect.setY(start.blockNumber() * self.get_marker_height())
rect.setWidth(self.sizeH... | def _draw_visible_area(self, painter) | Draw the visible area.
This method does not take folded blocks into account.
:type painter: QtGui.QPainter | 2.574303 | 2.616792 | 0.983763 |
if self.isVisible():
# fill background
self._background_brush = QtGui.QBrush(self.editor.background)
painter = QtGui.QPainter(self)
painter.fillRect(event.rect(), self._background_brush)
self._draw_messages(painter)
self._draw_visi... | def paintEvent(self, event) | Pains the messages and the visible area on the panel.
:param event: paint event infos | 3.544708 | 3.012605 | 1.176626 |
return self.editor.viewport().height() / TextHelper(
self.editor).line_count() | def get_marker_height(self) | Gets the height of message marker. | 19.955927 | 17.5431 | 1.137537 |
h = self.get_marker_height()
if h < 1:
h = 1
return QtCore.QSize(self.sizeHint().width() / 2, h) | def get_marker_size(self) | Gets the size of a message marker.
:return: QSize | 4.257068 | 3.801063 | 1.119968 |
mime = mimetypes.guess_type(path)[0]
if mime:
icon = mime.replace('/', '-')
# if system.WINDOWS:
# return icons.file()
if QtGui.QIcon.hasThemeIcon(icon):
icon = QtGui.QIcon.fromTheme(icon)
if not icon.isNull():
... | def mimetype_icon(path, fallback=None) | Tries to create an icon from theme using the file mimetype.
E.g.::
return self.mimetype_icon(
path, fallback=':/icons/text-x-python.png')
:param path: file path for which the icon must be created
:param fallback: fallback icon path (qrc or file system)
:ret... | 3.241319 | 3.827558 | 0.846837 |
client = Client(server=options.server, username=options.username, password=options.password)
print('Successfully connected to %s' % client.server)
print(client.si.CurrentTime())
client.logout() | def main(options) | A simple connection test to login and print the server time. | 5.472412 | 4.624848 | 1.183263 |
block = self.editor.document().findBlockByNumber(line)
try:
return block.userData().messages
except AttributeError:
return [] | def marker_for_line(self, line) | Returns the marker that is displayed at the specified line number if
any.
:param line: The marker line.
:return: Marker of None
:rtype: pyqode.core.Marker | 7.843385 | 9.946898 | 0.788526 |
global program, args, ret
print(os.getcwd())
ret = 0
if '--help' in sys.argv or '-h' in sys.argv or len(sys.argv) == 1:
print(__doc__)
else:
program = sys.argv[1]
args = sys.argv[2:]
if args:
ret = subprocess.call([program] + args)
else:
... | def main() | pyqode-console main function. | 2.710995 | 2.597819 | 1.043566 |
module_name = info['module']
fullname = info['fullname']
attribute_name = fullname.split('.')[-1]
base_url = 'https://github.com/fmenabe/python-dokuwiki/blob/'
if release.endswith('-dev'):
base_url += 'master/'
else:
base_url += version + '/'
filename = module_name.rep... | def linkcode_resolve(domain, info) | A simple function to find matching source code. | 3.013633 | 2.946462 | 1.022797 |
test_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
test_socket.bind(('127.0.0.1', 0))
free_port = int(test_socket.getsockname()[1])
test_socket.close()
return free_port | def pick_free_port() | Picks a free port | 1.776397 | 1.746775 | 1.016958 |
self._shared = reuse
if reuse and BackendManager.SHARE_COUNT:
self._port = BackendManager.LAST_PORT
self._process = BackendManager.LAST_PROCESS
BackendManager.SHARE_COUNT += 1
else:
if self.running:
self.stop()
... | def start(self, script, interpreter=sys.executable, args=None,
error_callback=None, reuse=False) | Starts the backend process.
The backend is a python script that starts a
:class:`pyqode.core.backend.JsonServer`. You must write the backend
script so that you can apply your own backend configuration.
The script can be run with a custom interpreter. The default is to use
sys.e... | 3.645761 | 3.450517 | 1.056584 |
if self._process is None:
return
if self._shared:
BackendManager.SHARE_COUNT -= 1
if BackendManager.SHARE_COUNT:
return
comm('stopping backend process')
# close all sockets
for s in self._sockets:
s._callbac... | def stop(self) | Stops the backend process. | 6.504625 | 6.103218 | 1.06577 |
if not self.running:
try:
# try to restart the backend if it crashed.
self.start(self.server_script, interpreter=self.interpreter,
args=self.args)
except AttributeError:
pass # not started yet
... | def send_request(self, worker_class_or_function, args, on_receive=None) | Requests some work to be done by the backend. You can get notified of
the work results by passing a callback (on_receive).
:param worker_class_or_function: Worker class or function
:param args: worker args, any Json serializable objects
:param on_receive: an optional callback executed w... | 6.48 | 6.332928 | 1.023223 |
try:
return (self._process is not None and
self._process.state() != self._process.NotRunning)
except RuntimeError:
return False | def running(self) | Tells whether the backend process is running.
:return: True if the process is running, otherwise False | 5.622985 | 6.210093 | 0.905459 |
files = self.get_value('list', [])
files.remove(filename)
self.set_value('list', files)
self.updated.emit() | def remove(self, filename) | Remove a file path from the list of recent files.
:param filename: Path of the file to remove | 4.46878 | 5.986345 | 0.746496 |
def unique(seq, idfun=None):
if idfun is None:
def idfun(x):
return x
# order preserving
seen = {}
result = []
for item in seq:
marker = idfun(item)
if marker in seen:
... | def get_value(self, key, default=None) | Reads value from QSettings
:param key: value key
:param default: default value.
:return: value | 2.741727 | 2.73449 | 1.002647 |
if value is None:
value = []
value = [os.path.normpath(pth) for pth in value]
self._settings.setValue('recent_files/%s' % key, value) | def set_value(self, key, value) | Set the recent files value in QSettings.
:param key: value key
:param value: new value | 4.966058 | 4.237953 | 1.171806 |
ret_val = []
files = self.get_value('list', [])
# filter files, remove files that do not exist anymore
for file in files:
if file is not None and os.path.exists(file):
if os.path.ismount(file) and \
sys.platform == 'win32' and ... | def get_recent_files(self) | Gets the list of recent files. (files that do not exists anymore
are automatically filtered) | 3.773651 | 3.285996 | 1.148404 |
files = self.get_recent_files()
try:
files.remove(file)
except ValueError:
pass
files.insert(0, file)
# discard old files
del files[self.max_recent_files:]
self.set_value('list', files)
self.updated.emit() | def open_file(self, file) | Adds a file to the list (and move it to the top of the list if the
file already exists)
:param file: file path to add the list of recent files. | 4.113209 | 3.839848 | 1.071191 |
self.clear()
self.recent_files_actions[:] = []
for file in self.manager.get_recent_files():
action = QtWidgets.QAction(self)
action.setText(os.path.split(file)[1])
action.setToolTip(file)
action.setStatusTip(file)
action.setDat... | def update_actions(self) | Updates the list of actions. | 2.541435 | 2.493474 | 1.019235 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.