text stringlengths 0 828 |
|---|
Returns: |
tuple: new_data, row_heights |
"""""" |
num_cols = len(data[0]) # number of columns |
# calculates row heights |
row_heights = [] |
for mlrow in data: |
row_height = 0 |
for j, cell in enumerate(mlrow): |
row_height = max(row_height, 1 if not isinstance(cell, (list, tuple)) else len(cell)) |
row_heights.append(row_height) |
num_lines = sum(row_heights) # line != row (rows are multiline) |
# rebuilds table data |
new_data = [[""""]*num_cols for i in range(num_lines)] |
i0 = 0 |
for row_height, mlrow in zip(row_heights, data): |
for j, cell in enumerate(mlrow): |
if not isinstance(cell, (list, tuple)): |
cell = [cell] |
for incr, x in enumerate(cell): |
new_data[i0+incr][j] = x |
i0 += row_height |
return new_data, row_heights" |
4574,"def rest_table(data, headers): |
"""""" |
Creates reStructuredText table (grid format), allowing for multiline cells |
Arguments: |
data -- [((cell000, cell001, ...), (cell010, cell011, ...), ...), ...] |
headers -- sequence of strings: (header0, header1, ...) |
**Note** Tolerant to non-strings |
**Note** Cells may or may not be multiline |
>>> rest_table([[""Eric"", ""Idle""], [""Graham"", ""Chapman""], [""Terry"", ""Gilliam""]], [""Name"", ""Surname""]) |
"""""" |
num_cols = len(headers) |
new_data, row_heights = expand_multirow_data(data) |
new_data = [[str(x) for x in row] for row in new_data] |
col_widths = [max([len(x) for x in col]) for col in zip(*new_data)] |
col_widths = [max(cw, len(s)) for cw, s in zip(col_widths, headers)] |
if any([x == 0 for x in col_widths]): |
raise RuntimeError(""Column widths ({}) has at least one zero"".format(col_widths)) |
num_lines = sum(row_heights) # line != row (rows are multiline) |
# horizontal lines |
hl0 = ""+""+""+"".join([""-""*(n+2) for n in col_widths])+""+"" |
hl1 = ""+""+""+"".join([""=""*(n+2) for n in col_widths])+""+"" |
frmtd = [""{0:{1}}"".format(x, width) for x, width in zip(headers, col_widths)] |
ret = [hl0, ""| ""+"" | "".join(frmtd)+"" |"", hl1] |
i0 = 0 |
for i, row_height in enumerate(row_heights): |
if i > 0: |
ret.append(hl0) |
for incr in range(row_height): |
frmtd = [""{0:{1}}"".format(x, width) for x, width in zip(new_data[i0+incr], col_widths)] |
ret.append(""| ""+"" | "".join(frmtd)+"" |"") |
i0 += row_height |
ret.append(hl0) |
return ret" |
4575,"def concept_adapter(obj, request): |
''' |
Adapter for rendering a :class:`skosprovider.skos.Concept` to json. |
:param skosprovider.skos.Concept obj: The concept to be rendered. |
:rtype: :class:`dict` |
''' |
p = request.skos_registry.get_provider(obj.concept_scheme.uri) |
language = request.params.get('language', request.locale_name) |
label = obj.label(language) |
return { |
'id': obj.id, |
'type': 'concept', |
'uri': obj.uri, |
'label': label.label if label else None, |
'concept_scheme': { |
'uri': obj.concept_scheme.uri, |
'labels': obj.concept_scheme.labels |
}, |
'labels': obj.labels, |
'notes': obj.notes, |
'sources': obj.sources, |
'narrower': _map_relations(obj.narrower, p, language), |
'broader': _map_relations(obj.broader, p, language), |
'related': _map_relations(obj.related, p, language), |
'member_of': _map_relations(obj.member_of, p, language), |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.