id
stringlengths 12
102
| prompt
stringlengths 221
20.1M
|
|---|---|
benedict.utils.type_util.is_json_serializable
|
You are a Python programmer working with a repository. Here is all the context you may find useful to complete the function:
#CURRENT FILE: python-benedict/benedict/utils/type_util.py
import pathlib
import re
from datetime import datetime
from decimal import Decimal
def is_list(val):
return isinstance(val, list)
def is_dict(val):
return isinstance(val, dict)
def is_string(val):
return isinstance(val, str)
def is_list_or_tuple(val):
return isinstance(val, (list, tuple))
def is_tuple(val):
return isinstance(val, tuple)
def is_dict_or_list_or_tuple(val):
return isinstance(val, (dict, list, tuple))
Based on the information above, please complete the function in the current file:
def is_json_serializable(val):
|
feedparser.urls.convert_to_idn
|
You are a Python programmer working with a repository. Here is all the context you may find useful to complete the function:
#CURRENT FILE: feedparser/feedparser/urls.py
import re
import urllib.parse
from .html import _BaseHTMLProcessor
def _urljoin(base, uri):
uri = _urifixer.sub(r'\1\3', uri)
try:
uri = urllib.parse.urljoin(base, uri)
except ValueError:
uri = ''
return uri
Based on the information above, please complete the function in the current file:
def convert_to_idn(url):
"""Convert a URL to IDN notation"""
# this function should only be called with a unicode string
# strategy: if the host cannot be encoded in ascii, then
# it'll be necessary to encode it in idn form
|
mistune.toc.add_toc_hook
|
You are a Python programmer working with a repository. Here is all the context you may find useful to complete the function:
#FILE: mistune/src/mistune/util.py
def striptags(s: str):
return _striptags_re.sub('', s)
#CURRENT FILE: mistune/src/mistune/toc.py
from .util import striptags
def normalize_toc_item(md, token):
text = token['text']
tokens = md.inline(text, {})
html = md.renderer(tokens, {})
text = striptags(html)
attrs = token['attrs']
return attrs['level'], attrs['id'], text
def render_toc_ul(toc):
"""Render a <ul> table of content HTML. The param "toc" should
be formatted into this structure::
[
(level, id, text),
]
For example::
[
(1, 'toc-intro', 'Introduction'),
(2, 'toc-install', 'Install'),
(2, 'toc-upgrade', 'Upgrade'),
(1, 'toc-license', 'License'),
]
"""
if not toc:
return ''
s = '<ul>\n'
levels = []
for level, k, text in toc:
item = '<a href="#{}">{}</a>'.format(k, text)
if not levels:
s += '<li>' + item
levels.append(level)
elif level == levels[-1]:
s += '</li>\n<li>' + item
elif level > levels[-1]:
s += '\n<ul>\n<li>' + item
levels.append(level)
else:
levels.pop()
while levels:
last_level = levels.pop()
if level == last_level:
s += '</li>\n</ul>\n</li>\n<li>' + item
levels.append(level)
break
elif level > last_level:
s += '</li>\n<li>' + item
levels.append(last_level)
levels.append(level)
break
else:
s += '</li>\n</ul>\n'
else:
levels.append(level)
s += '</li>\n<li>' + item
while len(levels) > 1:
s += '</li>\n</ul>\n'
levels.pop()
return s + '</li>\n</ul>\n'
Based on the information above, please complete the function in the current file:
def add_toc_hook(md, min_level=1, max_level=3, heading_id=None):
"""Add a hook to save toc items into ``state.env``. This is
usually helpful for doc generator::
import mistune
from mistune.toc import add_toc_hook, render_toc_ul
md = mistune.create_markdown(...)
add_toc_hook(md)
html, state = md.parse(text)
toc_items = state.env['toc_items']
toc_html = render_toc_ul(toc_items)
:param md: Markdown instance
:param min_level: min heading level
:param max_level: max heading level
:param heading_id: a function to generate heading_id
"""
|
mistune.plugins.table.table_in_quote
|
You are a Python programmer working with a repository. Here is all the context you may find useful to complete the function:
#CURRENT FILE: mistune/src/mistune/plugins/table.py
import re
from ..helpers import PREVENT_BACKSLASH
def render_table_row(renderer, text):
return '<tr>\n' + text + '</tr>\n'
def render_table_body(renderer, text):
return '<tbody>\n' + text + '</tbody>\n'
def render_table_cell(renderer, text, align=None, head=False):
if head:
tag = 'th'
else:
tag = 'td'
html = ' <' + tag
if align:
html += ' style="text-align:' + align + '"'
return html + '>' + text + '</' + tag + '>\n'
def _process_row(text, aligns):
cells = CELL_SPLIT.split(text)
if len(cells) != len(aligns):
return None
children = [
{
'type': 'table_cell',
'text': text.strip(),
'attrs': {'align': aligns[i], 'head': False}
}
for i, text in enumerate(cells)
]
return {'type': 'table_row', 'children': children}
def table(md):
"""A mistune plugin to support table, spec defined at
https://michelf.ca/projects/php-markdown/extra/#table
Here is an example:
.. code-block:: text
First Header | Second Header
------------- | -------------
Content Cell | Content Cell
Content Cell | Content Cell
:param md: Markdown instance
"""
md.block.register('table', TABLE_PATTERN, parse_table, before='paragraph')
md.block.register('nptable', NP_TABLE_PATTERN, parse_nptable, before='paragraph')
if md.renderer and md.renderer.NAME == 'html':
md.renderer.register('table', render_table)
md.renderer.register('table_head', render_table_head)
md.renderer.register('table_body', render_table_body)
md.renderer.register('table_row', render_table_row)
md.renderer.register('table_cell', render_table_cell)
def render_table_head(renderer, text):
return '<thead>\n<tr>\n' + text + '</tr>\n</thead>\n'
def parse_table(block, m, state):
pos = m.end()
header = m.group('table_head')
align = m.group('table_align')
thead, aligns = _process_thead(header, align)
if not thead:
return
rows = []
body = m.group('table_body')
for text in body.splitlines():
m = TABLE_CELL.match(text)
if not m: # pragma: no cover
return
row = _process_row(m.group(1), aligns)
if not row:
return
rows.append(row)
children = [thead, {'type': 'table_body', 'children': rows}]
state.append_token({'type': 'table', 'children': children})
return pos
def render_table(renderer, text):
return '<table>\n' + text + '</table>\n'
Based on the information above, please complete the function in the current file:
def table_in_quote(md):
"""Enable table plugin in block quotes."""
|
mistune.plugins.table.table_in_list
|
You are a Python programmer working with a repository. Here is all the context you may find useful to complete the function:
#CURRENT FILE: mistune/src/mistune/plugins/table.py
import re
from ..helpers import PREVENT_BACKSLASH
def _process_thead(header, align):
headers = CELL_SPLIT.split(header)
aligns = CELL_SPLIT.split(align)
if len(headers) != len(aligns):
return None, None
for i, v in enumerate(aligns):
if ALIGN_CENTER.match(v):
aligns[i] = 'center'
elif ALIGN_LEFT.match(v):
aligns[i] = 'left'
elif ALIGN_RIGHT.match(v):
aligns[i] = 'right'
else:
aligns[i] = None
children = [
{
'type': 'table_cell',
'text': text.strip(),
'attrs': {'align': aligns[i], 'head': True}
}
for i, text in enumerate(headers)
]
thead = {'type': 'table_head', 'children': children}
return thead, aligns
def render_table_row(renderer, text):
return '<tr>\n' + text + '</tr>\n'
def render_table_body(renderer, text):
return '<tbody>\n' + text + '</tbody>\n'
def render_table_cell(renderer, text, align=None, head=False):
if head:
tag = 'th'
else:
tag = 'td'
html = ' <' + tag
if align:
html += ' style="text-align:' + align + '"'
return html + '>' + text + '</' + tag + '>\n'
def _process_row(text, aligns):
cells = CELL_SPLIT.split(text)
if len(cells) != len(aligns):
return None
children = [
{
'type': 'table_cell',
'text': text.strip(),
'attrs': {'align': aligns[i], 'head': False}
}
for i, text in enumerate(cells)
]
return {'type': 'table_row', 'children': children}
def parse_nptable(block, m, state):
header = m.group('nptable_head')
align = m.group('nptable_align')
thead, aligns = _process_thead(header, align)
if not thead:
return
rows = []
body = m.group('nptable_body')
for text in body.splitlines():
row = _process_row(text, aligns)
if not row:
return
rows.append(row)
children = [thead, {'type': 'table_body', 'children': rows}]
state.append_token({'type': 'table', 'children': children})
return m.end()
def table_in_quote(md):
"""Enable table plugin in block quotes."""
md.block.insert_rule(md.block.block_quote_rules, 'table', before='paragraph')
md.block.insert_rule(md.block.block_quote_rules, 'nptable', before='paragraph')
def table(md):
"""A mistune plugin to support table, spec defined at
https://michelf.ca/projects/php-markdown/extra/#table
Here is an example:
.. code-block:: text
First Header | Second Header
------------- | -------------
Content Cell | Content Cell
Content Cell | Content Cell
:param md: Markdown instance
"""
md.block.register('table', TABLE_PATTERN, parse_table, before='paragraph')
md.block.register('nptable', NP_TABLE_PATTERN, parse_nptable, before='paragraph')
if md.renderer and md.renderer.NAME == 'html':
md.renderer.register('table', render_table)
md.renderer.register('table_head', render_table_head)
md.renderer.register('table_body', render_table_body)
md.renderer.register('table_row', render_table_row)
md.renderer.register('table_cell', render_table_cell)
def render_table_head(renderer, text):
return '<thead>\n<tr>\n' + text + '</tr>\n</thead>\n'
def parse_table(block, m, state):
pos = m.end()
header = m.group('table_head')
align = m.group('table_align')
thead, aligns = _process_thead(header, align)
if not thead:
return
rows = []
body = m.group('table_body')
for text in body.splitlines():
m = TABLE_CELL.match(text)
if not m: # pragma: no cover
return
row = _process_row(m.group(1), aligns)
if not row:
return
rows.append(row)
children = [thead, {'type': 'table_body', 'children': rows}]
state.append_token({'type': 'table', 'children': children})
return pos
def render_table(renderer, text):
return '<table>\n' + text + '</table>\n'
Based on the information above, please complete the function in the current file:
def table_in_list(md):
"""Enable table plugin in list."""
|
xmnlp.utils.parallel_handler
| "You are a Python programmer working with a repository. Here is all the context you may find useful (...TRUNCATED)
|
parsel.utils.shorten
| "You are a Python programmer working with a repository. Here is all the context you may find useful (...TRUNCATED)
|
parsel.xpathfuncs.set_xpathfunc
| "You are a Python programmer working with a repository. Here is all the context you may find useful (...TRUNCATED)
|
dominate.dom_tag._get_thread_context
| "You are a Python programmer working with a repository. Here is all the context you may find useful (...TRUNCATED)
|
dominate.util.system
| "You are a Python programmer working with a repository. Here is all the context you may find useful (...TRUNCATED)
|
End of preview. Expand
in Data Studio
README.md exists but content is empty.
- Downloads last month
- 2