Instruction stringlengths 362 7.83k | output_code stringlengths 1 945 |
|---|---|
Predict the next line for this snippet: <|code_start|> assert query_html_doc('', 'false() = boolean(false())') == expected_result('true')
assert query_html_doc('', 'boolean(0 div 0)') == expected_result('false')
def test_boolean_function_converts_node_sets_according_to_w3c_rules():
assert query_html_doc('<... | <p id="one"> |
Predict the next line for this snippet: <|code_start|> </div>""")
def test_tag_node_test_selects_ancestors():
html_body = """
<div id="id">
<p></p>
</div>"""
actual = query_html_doc(html_body, '/html/body/div/p/ancestor::*')
assert actual == expected_result("""
<html>
<body>
... | def test_text_node_test_selects_disjoint_text_nodes(): |
Given snippet: <|code_start|> <p>text</p>
</div>"""
actual = query_html_doc(html_body, '/html/body/descendant::*')
assert actual == expected_result("""
<div>
<p>
text
</p>
</div>
<p>
text
</p>""")
def test_tag_node_test_selects_parent():
html_body = """
... | html_body = """ |
Given snippet: <|code_start|>
def test_hash_can_contain_key_values_that_are_other_computed_json_objects():
actual = json.loads(query_html_doc('', 'hash {a_hash: hash {foo: "bar"}, an_array: array {"one", 2}}'))
assert 'a_hash' in actual
assert 'an_array' in actual
assert isinstance(actual['a_hash'], di... | assert actual[0] == 'one' |
Given the code snippet: <|code_start|>
class HqueryEvaluationError(RuntimeError):
@classmethod
def must_be_node_set(cls, obj):
if not is_node_set(obj):
raise HqueryEvaluationError('Expected a node set, but found a(n) {0}'.format(obj.__class__.__name__))
<|code_end|>
, generate the next li... | @classmethod |
Predict the next line for this snippet: <|code_start|>
class HqueryEvaluationError(RuntimeError):
@classmethod
def must_be_node_set(cls, obj):
if not is_node_set(obj):
raise HqueryEvaluationError('Expected a node set, but found a(n) {0}'.format(obj.__class__.__name__))
@classmethod
<|... | def must_be_node_set_or_sequence(cls, obj): |
Using the snippet: <|code_start|>def test_flwor_with_multiple_return_clauses_is_a_syntax_error():
with raises(HquerySyntaxError):
query_html_doc('', 'let $x := 0 return $x return $x + 1')
def test_abbreviated_flowr_provides_expected_iteration_variable_in_value_clause():
html_body = """
<p>one</p>
... | one |
Given snippet: <|code_start|> <p>one</p>
<p>two</p>
<p>three</p>"""
assert query_html_doc(html_body, 'for $x in //p return $x/text()') == expected_result("""
one
two
three""")
def test_flwor_variable_declaration_within_iteration():
query = 'for $x in (1 to 2) let $y := concat("Thing ", ... | <div> |
Predict the next line for this snippet: <|code_start|> </section>"""
assert query_html_doc(html_body, 'for $x in //section return $x/div') == expected_result("""
<div>
<div>
foo
</div>
</div>
<div>
<div>
bar
</div>
</div>""")
assert query_html_doc(html_body, ... | </div>""") |
Here is a snippet: <|code_start|> <title>Introduction</title>
</chapter>
<chapter>not selected</chapter>
<chapter>
<title>Author's Note</title>
</chapter>
<chapter>
<title>Introduction</title>
<content>Hello, I'm chapter.</content>
... | <chapter> |
Continue the code snippet: <|code_start|> assert query_context_node(html, '*') == expected_result("""
<element>
selected
</element>
<para>
also selected
</para>""")
def test_selects_all_text_node_children_of_the_context_node():
html = """
<context>
first
<element>s... | first="first value" |
Next line prediction: <|code_start|> five point two
</section>""")
def test_selects_the_para_element_descendants_of_the_chapter_element_children_of_the_context_node():
html = """
<context>
<para>not selected</para>
<chapter>
<para>
<para>selected</para>
... | </para> |
Predict the next line for this snippet: <|code_start|>
def test_location_path_works_as_interpolated_string_expression():
assert query_html_doc("<div>world</div>", '`Hello, ${//div/text()}!`') == expected_result('Hello, world!')
def test_element_node_becomes_normalized_text_contents_in_interpolated_string():
... | <p>two</p> |
Continue the code snippet: <|code_start|> assert query_html_doc(html_body, '`${tru:23:?://p}`') == expected_result('The quick brown fox?')
def test_truncate_filter_defaults_to_no_suffix():
html_body = '<p>short, sharp shock</p>'
assert query_html_doc(html_body, '`${tru:15:://p}`') == expected_result('short... | def test_character_escape_is_not_prematurely_decoded_in_interpolated_string(): |
Next line prediction: <|code_start|> raise HqueryEvaluationError('Attempted to construct a JSON array based on a(n) {0} object'.format(
contents.__class__.__name__))
self.contents = contents
def __repr__(self):
return 'ARRAY {0}'.format(repr(self.contents))
def __s... | def _make_array_item(self, value): |
Next line prediction: <|code_start|>
class JsonArray:
def __init__(self, contents):
if not isinstance(contents, list):
raise HqueryEvaluationError('Attempted to construct a JSON array based on a(n) {0} object'.format(
contents.__class__.__name__))
self.contents = conte... | def __repr__(self): |
Continue the code snippet: <|code_start|>class JsonArray:
def __init__(self, contents):
if not isinstance(contents, list):
raise HqueryEvaluationError('Attempted to construct a JSON array based on a(n) {0} object'.format(
contents.__class__.__name__))
self.contents = con... | def evaluate(self): |
Predict the next line after this snippet: <|code_start|>
class JsonArray:
def __init__(self, contents):
if not isinstance(contents, list):
raise HqueryEvaluationError('Attempted to construct a JSON array based on a(n) {0} object'.format(
<|code_end|>
using the current file's imports:
import... | contents.__class__.__name__)) |
Next line prediction: <|code_start|>class ComputedJsonArrayConstructor:
def __init__(self):
self.contents = None
def set_contents(self, expression_fn):
if self.contents is not None:
raise HquerySyntaxError('computed JSON array constructor already has contents')
self.conten... | else: |
Here is a snippet: <|code_start|> raise HqueryEvaluationError('Attempted to construct a JSON array based on a(n) {0} object'.format(
contents.__class__.__name__))
self.contents = contents
def __repr__(self):
return 'ARRAY {0}'.format(repr(self.contents))
def __str_... | def _make_array_item(self, value): |
Predict the next line after this snippet: <|code_start|>
class JsonArray:
def __init__(self, contents):
if not isinstance(contents, list):
raise HqueryEvaluationError('Attempted to construct a JSON array based on a(n) {0} object'.format(
contents.__class__.__name__))
s... | self.contents = None |
Continue the code snippet: <|code_start|> raise HqueryEvaluationError('Attempted to construct a JSON array based on a(n) {0} object'.format(
contents.__class__.__name__))
self.contents = contents
def __repr__(self):
return 'ARRAY {0}'.format(repr(self.contents))
de... | def _make_array_item(self, value): |
Given the following code snippet before the placeholder: <|code_start|>
class JsonArray:
def __init__(self, contents):
if not isinstance(contents, list):
raise HqueryEvaluationError('Attempted to construct a JSON array based on a(n) {0} object'.format(
contents.__class__.__nam... | return 'ARRAY {0}'.format(repr(self.contents)) |
Predict the next line after this snippet: <|code_start|>
class JsonArray:
def __init__(self, contents):
if not isinstance(contents, list):
raise HqueryEvaluationError('Attempted to construct a JSON array based on a(n) {0} object'.format(
contents.__class__.__name__))
s... | return 'ARRAY {0}'.format(repr(self.contents)) |
Using the snippet: <|code_start|>class JsonArray:
def __init__(self, contents):
if not isinstance(contents, list):
raise HqueryEvaluationError('Attempted to construct a JSON array based on a(n) {0} object'.format(
contents.__class__.__name__))
self.contents = contents
... | def evaluate(self): |
Given the following code snippet before the placeholder: <|code_start|>
def test_tolerates_latin_characters_in_element_contents(capsys, mocker):
mocker.patch('hq.hq.docopt').return_value = simulate_args_dict(expression='//div')
mocker.patch('sys.stdin.read').return_value = wrap_html_body(u"""
<div>
... | <div> |
Based on the snippet: <|code_start|>
def test_tolerates_latin_characters_in_element_contents(capsys, mocker):
mocker.patch('hq.hq.docopt').return_value = simulate_args_dict(expression='//div')
mocker.patch('sys.stdin.read').return_value = wrap_html_body(u"""
<|code_end|>
, predict the immediate next line with ... | <div> |
Using the snippet: <|code_start|>
def test_tolerates_latin_characters_in_element_contents(capsys, mocker):
mocker.patch('hq.hq.docopt').return_value = simulate_args_dict(expression='//div')
mocker.patch('sys.stdin.read').return_value = wrap_html_body(u"""
<div>
T\xeate\xa0\xe0\xa0t\xeate
</div>... | def test_tolerates_latin_characters_in_comments(capsys, mocker): |
Predict the next line for this snippet: <|code_start|>
def test_tolerates_latin_characters_in_element_contents(capsys, mocker):
mocker.patch('hq.hq.docopt').return_value = simulate_args_dict(expression='//div')
mocker.patch('sys.stdin.read').return_value = wrap_html_body(u"""
<|code_end|>
with the help of cur... | <div> |
Based on the snippet: <|code_start|>
def convert_results_to_output_text(results, pretty=True, preserve_space=False):
if is_sequence(results):
return '\n'.join(value_object_to_text(object, pretty, preserve_space) for object in results)
else:
return value_object_to_text(results, pretty, preserve... | def value_object_to_text(obj, pretty, preserve_space): |
Here is a snippet: <|code_start|>
def convert_results_to_output_text(results, pretty=True, preserve_space=False):
if is_sequence(results):
return '\n'.join(value_object_to_text(object, pretty, preserve_space) for object in results)
<|code_end|>
. Write the next line using the current file imports:
from b... | else: |
Here is a snippet: <|code_start|>
def convert_results_to_output_text(results, pretty=True, preserve_space=False):
if is_sequence(results):
return '\n'.join(value_object_to_text(object, pretty, preserve_space) for object in results)
else:
return value_object_to_text(results, pretty, preserve_sp... | else: |
Here is a snippet: <|code_start|>
def convert_results_to_output_text(results, pretty=True, preserve_space=False):
if is_sequence(results):
return '\n'.join(value_object_to_text(object, pretty, preserve_space) for object in results)
else:
return value_object_to_text(results, pretty, preserve_sp... | return str(obj) |
Given the code snippet: <|code_start|>
class ComputedHtmlAttributeConstructor:
def __init__(self, name):
self.name = name
self.contents = None
def set_content(self, expression_fn):
<|code_end|>
, generate the next line using the imports in this file:
from hq.hquery.evaluation_error import H... | if self.contents is not None: |
Given the code snippet: <|code_start|> self.name = name
self.contents = None
def set_content(self, expression_fn):
if self.contents is not None:
raise HquerySyntaxError('Computed attribute constructor already has contents')
self.contents = expression_fn
def evaluat... | return '{0}{1}{2}'.format(so_far, ' ' if len(so_far) > 0 else '', more_content) |
Given the code snippet: <|code_start|>
class ComputedHtmlAttributeConstructor:
def __init__(self, name):
self.name = name
self.contents = None
def set_content(self, expression_fn):
if self.contents is not None:
raise HquerySyntaxError('Computed attribute constructor alrea... | 'Cannot use {0} as a content object in a computed attribute constructor'.format(value_desc) |
Next line prediction: <|code_start|>
class ComputedHtmlAttributeConstructor:
def __init__(self, name):
self.name = name
self.contents = None
def set_content(self, expression_fn):
if self.contents is not None:
raise HquerySyntaxError('Computed attribute constructor already... | result = '' |
Using the snippet: <|code_start|>
class ComputedHtmlAttributeConstructor:
def __init__(self, name):
self.name = name
<|code_end|>
, determine the next line of code. You have imports:
from hq.hquery.evaluation_error import HqueryEvaluationError
from hq.hquery.object_type import is_string, is_number, is_bo... | self.contents = None |
Next line prediction: <|code_start|> self.name = name
self.contents = None
def set_content(self, expression_fn):
if self.contents is not None:
raise HquerySyntaxError('Computed attribute constructor already has contents')
self.contents = expression_fn
def evaluate(... | return '{0}{1}{2}'.format(so_far, ' ' if len(so_far) > 0 else '', more_content) |
Given the code snippet: <|code_start|>
class ComputedHtmlAttributeConstructor:
def __init__(self, name):
self.name = name
self.contents = None
def set_content(self, expression_fn):
if self.contents is not None:
raise HquerySyntaxError('Computed attribute constructor alrea... | ) |
Here is a snippet: <|code_start|>
class ComputedHtmlAttributeConstructor:
def __init__(self, name):
self.name = name
self.contents = None
def set_content(self, expression_fn):
if self.contents is not None:
raise HquerySyntaxError('Computed attribute constructor already ha... | else: |
Based on the snippet: <|code_start|>
class ComputedHtmlAttributeConstructor:
def __init__(self, name):
self.name = name
self.contents = None
def set_content(self, expression_fn):
if self.contents is not None:
raise HquerySyntaxError('Computed attribute constructor already... | result = self._append_to_contents(result, value.value) |
Predict the next line for this snippet: <|code_start|>
class ComputedHtmlAttributeConstructor:
def __init__(self, name):
self.name = name
self.contents = None
<|code_end|>
with the help of current file imports:
from hq.hquery.evaluation_error import HqueryEvaluationError
from hq.hquery.object_... | def set_content(self, expression_fn): |
Based on the snippet: <|code_start|> self.name = name
self.contents = None
def set_content(self, expression_fn):
if self.contents is not None:
raise HquerySyntaxError('Computed attribute constructor already has contents')
self.contents = expression_fn
def evaluate(... | return '{0}{1}{2}'.format(so_far, ' ' if len(so_far) > 0 else '', more_content) |
Based on the snippet: <|code_start|>from __future__ import print_function
indent_level = 0
def set_verbosity(verbose):
setattr(settings, 'VERBOSE', verbose)
def push_indent():
global indent_level
indent_level += 2
def pop_indent():
global indent_level
<|code_end|>
, predict the immediate next l... | indent_level -= 2 |
Given the code snippet: <|code_start|>from __future__ import print_function
indent_level = 0
def set_verbosity(verbose):
setattr(settings, 'VERBOSE', verbose)
def push_indent():
<|code_end|>
, generate the next line using the imports in this file:
import sys
from .config import settings
from .string_util i... | global indent_level |
Here is a snippet: <|code_start|>
def test_if_then_else_works_with_literal_conditions():
assert query_html_doc('', 'if (true()) then "foo" else "bar"') == 'foo'
assert query_html_doc('', 'if ("") then "foo" else "bar"') == 'bar'
assert query_html_doc('', 'if (0.001) then "foo" else "bar"') == 'foo'
def t... | eekaboo |
Here is a snippet: <|code_start|>
def test_if_then_else_works_with_literal_conditions():
assert query_html_doc('', 'if (true()) then "foo" else "bar"') == 'foo'
assert query_html_doc('', 'if ("") then "foo" else "bar"') == 'bar'
assert query_html_doc('', 'if (0.001) then "foo" else "bar"') == 'foo'
def t... | 1 |
Next line prediction: <|code_start|> assert query_html_doc('', '(2+3)*3') == expected_result('15')
assert query_html_doc('', '3*(3+2)') == expected_result('15')
assert query_html_doc('', '2+3*3 != (2+3)*3') == expected_result('true')
def test_union_operator_combines_node_sets():
html_body = """
<di... | </div> |
Given snippet: <|code_start|>
def test_parentheses_boost_precedence():
assert query_html_doc('', '(2+3)*3') == expected_result('15')
assert query_html_doc('', '3*(3+2)') == expected_result('15')
assert query_html_doc('', '2+3*3 != (2+3)*3') == expected_result('true')
def test_union_operator_combines_node... | <div>three</div>""" |
Predict the next line for this snippet: <|code_start|>exports = ('boolean', 'false', 'not_', 'true')
class boolean:
def __init__(self, obj):
if is_node_set(obj):
self.value = len(obj) > 0
elif is_number(obj):
f = float(obj)
self.value = bool(f) and not isnan(f)... | def false(): |
Predict the next line for this snippet: <|code_start|>
exports = ('boolean', 'false', 'not_', 'true')
class boolean:
def __init__(self, obj):
if is_node_set(obj):
self.value = len(obj) > 0
elif is_number(obj):
f = float(obj)
self.value = bool(f) and not isnan... | else: |
Based on the snippet: <|code_start|>exports = ('boolean', 'false', 'not_', 'true')
class boolean:
def __init__(self, obj):
if is_node_set(obj):
self.value = len(obj) > 0
elif is_number(obj):
f = float(obj)
self.value = bool(f) and not isnan(f)
else:
... | def false(): |
Given the following code snippet before the placeholder: <|code_start|>
class ComputedHashKeyValueConstructor:
def __init__(self, key):
self.key = key
self.value_fn = None
def set_value(self, fn):
self.value_fn = fn
def evaluate(self):
verbose_print('Evaluating value ex... | return HashKeyValue(self.key, value) |
Next line prediction: <|code_start|>
class ComputedHtmlElementConstructor:
def __init__(self, name):
self.name = name
self.contents = None
def set_content(self, expression_fn):
if self.contents is not None:
raise HquerySyntaxError('Computed element constructor already has... | result.append(self._clone_tag(value)) |
Based on the snippet: <|code_start|>
class ComputedHtmlElementConstructor:
def __init__(self, name):
self.name = name
self.contents = None
def set_content(self, expression_fn):
if self.contents is not None:
raise HquerySyntaxError('Computed element constructor already has... | 'Cannot use {0} as a content object in a computed element constructor'.format(value_desc) |
Given the code snippet: <|code_start|>
def set_content(self, expression_fn):
if self.contents is not None:
raise HquerySyntaxError('Computed element constructor already has contents')
self.contents = expression_fn
def evaluate(self):
soup = BeautifulSoup('<{0}></{0}>'.form... | soup = BeautifulSoup(str(tag), 'html.parser') |
Here is a snippet: <|code_start|>
class ComputedHtmlElementConstructor:
def __init__(self, name):
self.name = name
self.contents = None
def set_content(self, expression_fn):
if self.contents is not None:
raise HquerySyntaxError('Computed element constructor already has co... | result = getattr(soup, self.name) |
Predict the next line after this snippet: <|code_start|>
class ComputedHtmlElementConstructor:
def __init__(self, name):
self.name = name
self.contents = None
def set_content(self, expression_fn):
if self.contents is not None:
raise HquerySyntaxError('Computed element con... | result.append(self._clone_tag(value)) |
Given the following code snippet before the placeholder: <|code_start|>
class ComputedHtmlElementConstructor:
def __init__(self, name):
self.name = name
self.contents = None
def set_content(self, expression_fn):
if self.contents is not None:
raise HquerySyntaxError('Compu... | ) |
Given the code snippet: <|code_start|>
class ComputedHtmlElementConstructor:
def __init__(self, name):
self.name = name
self.contents = None
def set_content(self, expression_fn):
if self.contents is not None:
raise HquerySyntaxError('Computed element constructor already h... | def evaluate(self): |
Given snippet: <|code_start|>
class ComputedHtmlElementConstructor:
def __init__(self, name):
self.name = name
self.contents = None
def set_content(self, expression_fn):
if self.contents is not None:
raise HquerySyntaxError('Computed element constructor already has conten... | result[value.name] = value.value |
Based on the snippet: <|code_start|>
class ComputedHtmlElementConstructor:
def __init__(self, name):
self.name = name
self.contents = None
def set_content(self, expression_fn):
if self.contents is not None:
raise HquerySyntaxError('Computed element constructor already has... | self.contents = expression_fn |
Here is a snippet: <|code_start|>
class FunctionSupport:
all_functions = None
def call_function(self, name, *args):
self._load_all_functions()
py_name = name.replace('-', '_')
<|code_end|>
. Write the next line using the current file imports:
import os
import re
from inspect import isclas... | try: |
Based on the snippet: <|code_start|>
class FunctionSupport:
all_functions = None
def call_function(self, name, *args):
self._load_all_functions()
py_name = name.replace('-', '_')
try:
<|code_end|>
, predict the immediate next line with the help of imports:
import os
import re
from... | fn = self.all_functions[py_name] |
Next line prediction: <|code_start|>
exports = ('ceiling', 'floor', 'number', 'round_', 'sum')
class number:
def __init__(self, obj):
if isinstance(obj, number):
self.value = obj.value
elif is_boolean(obj):
<|code_end|>
. Use current file imports:
(import math
from hq.hquery.evaluat... | self.value = 1 if obj else 0 |
Next line prediction: <|code_start|> def __repr__(self):
return 'number({0})'.format(str(self.value))
@staticmethod
def _int_or_float(numeric_value):
if isinstance(numeric_value, int) or numeric_value % 1 != 0:
return numeric_value
else:
return int(numeric_val... | return number(round(value.value, 0 if len(args) < 2 else args[1].value)) |
Given the following code snippet before the placeholder: <|code_start|>
exports = ('ceiling', 'floor', 'number', 'round_', 'sum')
class number:
def __init__(self, obj):
if isinstance(obj, number):
self.value = obj.value
elif is_boolean(obj):
self.value = 1 if obj else 0
... | if result == 'nan': |
Next line prediction: <|code_start|> return float(self.value)
def __int__(self):
return int(self.value)
def __str__(self):
result = str(self.value)
if result == 'nan':
result = 'NaN'
return result
def __hash__(self):
return self.value.__hash__()
... | other = self._value_of_other_operand(other) |
Next line prediction: <|code_start|> return number(self.value / other)
def __mod__(self, other):
return number(self.value % self._value_of_other_operand(other))
def __eq__(self, other):
return self.value == self._value_of_other_operand(other)
def __ge__(self, other):
re... | @staticmethod |
Given the code snippet: <|code_start|>
exports = ('ceiling', 'floor', 'number', 'round_', 'sum')
class number:
def __init__(self, obj):
if isinstance(obj, number):
self.value = obj.value
elif is_boolean(obj):
self.value = 1 if obj else 0
elif is_node_set(obj) or i... | return float(self.value) |
Next line prediction: <|code_start|> return int(numeric_value)
@staticmethod
def _value_of_other_operand(other):
return other.value if is_number(other) else other
def ceiling(value):
return number(math.ceil(value.value))
def floor(value):
return number(math.floor(value.value))
... | if len(args) >= 2: |
Here is a snippet: <|code_start|>
def test_preserve_space_flag_turns_off_space_normalization(capsys, mocker):
hquery = '`${//p}`'
content_with_spaces = ' PyCharm rocks! '
mocker.patch('sys.stdin.read').return_value = wrap_html_body('<p>{0}</p>'.format(content_with_spaces))
mocker.patch('hq.h... | assert actual == u'non breaking spaces?' |
Given the code snippet: <|code_start|>
def test_reading_input_from_a_file_instead_of_stdin(capsys, mocker):
expected_filename = 'filename.html'
mocked_open = mock_open(read_data=wrap_html_body('<p>foo</p>'))
mocker.patch('hq.hq.docopt').return_value = simulate_args_dict(
expression='//p/text()', fil... | assert actual == 'foo' |
Predict the next line after this snippet: <|code_start|> def gather_css_class(self, node):
return self.gather_child(node)
def gather_descendant(self, node):
if hasattr(node, 'descendants'):
return list(node.descendants)
else:
return []
def gather_descendant... | else: |
Next line prediction: <|code_start|> result.extend(self.gather_descendant(sibling))
node = node.parent
return result
def gather_following_sibling(self, node):
if hasattr(node, 'next_siblings'):
return list(node.next_siblings)
else:
return ... | if hasattr(node, 'previous_siblings'): |
Here is a snippet: <|code_start|>
self.repr = '{0}{1}'.format(self.repr, '' if name_test or value == '*' else '()')
def __repr__(self):
return self.repr
def apply(self, axis, node):
nodes = getattr(self, 'gather_{0}'.format(axis.name))(node)
return [node for node in nodes if ... | def gather_child(self, node): |
Given the code snippet: <|code_start|>
def _accept_principal_node_type(node, axis=None):
return is_attribute_node(node) if axis == Axis.attribute else is_tag_node(node)
def _make_axis_agnostic_accept_fn(fn):
def evaluate(node, axis=None):
return fn(node)
return evaluate
def _make_name_accept_f... | if name_test: |
Next line prediction: <|code_start|> return result
def gather_following_sibling(self, node):
if hasattr(node, 'next_siblings'):
return list(node.next_siblings)
else:
return []
def gather_parent(self, node):
if hasattr(node, 'parent') and node.parent is ... | else: |
Using the snippet: <|code_start|> def gather_descendant_or_self(self, node):
result = self.gather_self(node)
result.extend(self.gather_descendant(node))
return result
def gather_following(self, node):
result = []
while is_tag_node(node):
for sibling in node.n... | def gather_preceding(self, node): |
Predict the next line after this snippet: <|code_start|>
def apply(self, axis, node):
nodes = getattr(self, 'gather_{0}'.format(axis.name))(node)
return [node for node in nodes if self.accept_fn(node, axis=axis)]
def gather_ancestor(self, node):
if hasattr(node, 'parents'):
... | return [] |
Continue the code snippet: <|code_start|> result = []
while is_tag_node(node):
for sibling in node.next_siblings:
result.append(sibling)
result.extend(self.gather_descendant(sibling))
node = node.parent
return result
def gather_followi... | return result |
Here is a snippet: <|code_start|> return type_fn(node) and node.name.lower() == value
return evaluate
class NodeTest:
def __init__(self, value, name_test=False):
value = value.lower()
self.repr = value
self.is_name_test = name_test
if name_test:
self.ac... | nodes = getattr(self, 'gather_{0}'.format(axis.name))(node) |
Predict the next line for this snippet: <|code_start|> return 'ROOT DOCUMENT'
elif is_tag_node(obj):
return u'ELEMENT {0}'.format(debug_dump_long_string(str(obj)))
elif is_attribute_node(obj):
return 'ATTRIBUTE {0}="{1}"'.format(obj.name, debug_dump_long_string(obj.value))
elif is_tex... | add_space = False |
Predict the next line after this snippet: <|code_start|>
class AttributeNode:
def __init__(self, name, value):
self.name = name
self.value = ' '.join(value) if isinstance(value, list) else value
def __repr__(self):
return 'AttributeNode("{0}", "{1}")'.format(self.name, self.value)
... | if hasattr(node, 'hq_attrs') and _isnt_root_with_odd_ghost_hq_attrs_on_it_for_reasons_i_dont_understand(node): |
Continue the code snippet: <|code_start|> return '{0} => {0}'.format(union_str)
def evaluate(self):
verbose_print('Evaluating union decomposition ({} clauses)'.format(len(self.mapping_generators)),
indent_after=True)
sequence = make_sequence(self.union_expression())
... | return result |
Given the code snippet: <|code_start|> sequence = make_sequence(self.union_expression())
result = []
for item in sequence:
verbose_print(lambda: u'Visiting item {0}'.format(debug_dump_anything(item)), indent_after=True)
with variable_scope():
push_variabl... | def set_union_expression(self, ug): |
Predict the next line for this snippet: <|code_start|> def __init__(self):
self.mapping_generators = None
self.union_expression = None
def __str__(self):
union_str = ' | '.join('<expr>' * len(self.mapping_generators))
return '{0} => {0}'.format(union_str)
def evaluate(self... | 'Mapping yielded {0} results for this visit'.format( |
Continue the code snippet: <|code_start|> verbose_print('Evaluating union decomposition ({} clauses)'.format(len(self.mapping_generators)),
indent_after=True)
sequence = make_sequence(self.union_expression())
result = []
for item in sequence:
verbose_pr... | self.mapping_generators = mgs |
Next line prediction: <|code_start|>
class UnionDecomposition:
def __init__(self):
self.mapping_generators = None
self.union_expression = None
def __str__(self):
<|code_end|>
. Use current file imports:
(from hq.hquery.evaluation_error import HqueryEvaluationError
from hq.hquery.object_type... | union_str = ' | '.join('<expr>' * len(self.mapping_generators)) |
Given the following code snippet before the placeholder: <|code_start|> verbose_print('Evaluating union decomposition ({} clauses)'.format(len(self.mapping_generators)),
indent_after=True)
sequence = make_sequence(self.union_expression())
result = []
for item in se... | self.mapping_generators = mgs |
Given the following code snippet before the placeholder: <|code_start|>
def evaluate_across_contexts(node_set, expression_fn):
HqueryEvaluationError.must_be_node_set(node_set)
node_set_len = len(node_set)
ragged = [evaluate_in_context(node, expression_fn, position=index+1, size=node_set_len)
<|code_end|>
... | for index, node in enumerate(node_set)] |
Predict the next line for this snippet: <|code_start|>
def evaluate_across_contexts(node_set, expression_fn):
HqueryEvaluationError.must_be_node_set(node_set)
node_set_len = len(node_set)
ragged = [evaluate_in_context(node, expression_fn, position=index+1, size=node_set_len)
<|code_end|>
with the help of... | for index, node in enumerate(node_set)] |
Given the following code snippet before the placeholder: <|code_start|>
def evaluate_across_contexts(node_set, expression_fn):
HqueryEvaluationError.must_be_node_set(node_set)
node_set_len = len(node_set)
ragged = [evaluate_in_context(node, expression_fn, position=index+1, size=node_set_len)
... | result = expression_fn() |
Given the following code snippet before the placeholder: <|code_start|>
def evaluate_across_contexts(node_set, expression_fn):
HqueryEvaluationError.must_be_node_set(node_set)
node_set_len = len(node_set)
ragged = [evaluate_in_context(node, expression_fn, position=index+1, size=node_set_len)
... | return result |
Based on the snippet: <|code_start|>
def evaluate_across_contexts(node_set, expression_fn):
HqueryEvaluationError.must_be_node_set(node_set)
node_set_len = len(node_set)
<|code_end|>
, predict the immediate next line with the help of imports:
from hq.hquery.evaluation_error import HqueryEvaluationError
from ... | ragged = [evaluate_in_context(node, expression_fn, position=index+1, size=node_set_len) |
Predict the next line for this snippet: <|code_start|>
def test_simple_element_construction_with_string_content():
assert query_html_doc('', 'element foo { "bar" }') == expected_result("""
<foo>
bar
</foo>""")
def test_element_constructor_accepts_numbers_and_booleans():
assert query_html_doc('',... | 98.6 |
Predict the next line after this snippet: <|code_start|> </div>"""
assert query_html_doc(html_body, 'element hello { //div }') == expected_result("""
<hello>
<div>
<p>
Hello, world!
</p>
<div>
other div
</div>
</div>
<div>
other div
</div>
<... | contents |
Given the following code snippet before the placeholder: <|code_start|> assert query_html_doc('', '2 <=2') == 'true'
assert query_html_doc('', '1.999<= 2') == 'true'
assert query_html_doc('', '2.001 <= 2') == 'false'
def test_relational_comparison_of_booleans_with_one_another_and_with_other_non_node_set_pr... | <div>11</div>""" |
Next line prediction: <|code_start|>
def capture_console_output(capsys, strip=True):
output, errors = capsys.readouterr()
output = output.rstrip('\n')
return eliminate_blank_lines(output.strip()) if strip else output, eliminate_blank_lines(errors.strip())
def eliminate_blank_lines(s):
return '\n'.jo... | '-u': False, |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.