Format Mecab output into a nice data structure, based on Janome.
433648
def detailed_tokens(tokenizer, text):
    """"""
    node = tokenizer.parseToNode(text)
    node = node.next  # first node is beginning of sentence and empty, skip it
    words = []
    while node.posid != 0:
        surface = node.surface
        base = surface  # a default value. Updated if available later.
        parts = node.feature.split(",")
        pos = ",".join(parts[0:4])
        if len(parts) > 7:
            # this information is only available for words in the tokenizer
            # dictionary
            base = parts[7]
        words.append(ShortUnitWord(surface, base, pos))
        node = node.next
    return words
1041657
def assemble_pysb():
    """"""
    if request.method == 'OPTIONS':
        return {}
    response = request.body.read().decode('utf-8')
    body = json.loads(response)
    stmts_json = body.get('statements')
    export_format = body.get('export_format')
    stmts = stmts_from_json(stmts_json)
    pa = PysbAssembler()
    pa.add_statements(stmts)
    pa.make_model()
    try:
        for m in pa.model.monomers:
            pysb_assembler.set_extended_initial_condition(pa.model, m, 0)
    except Exception as e:
        logger.exception(e)

    if not export_format:
        model_str = pa.print_model()
    elif export_format in ('kappa_im', 'kappa_cm'):
        fname = 'model_%s.png' % export_format
        root = os.path.dirname(os.path.abspath(fname))
        graph = pa.export_model(format=export_format, file_name=fname)
        with open(fname, 'rb') as fh:
            data = 'data:image/png;base64,%s' % \
                base64.b64encode(fh.read()).decode() 
            return {'image': data}
    else:
        try:
            model_str = pa.export_model(format=export_format)
        except Exception as e:
            logger.exception(e)
            model_str = ''
    res = {'model': model_str}
    return res
688528
def data_json(self, pretty=False):
        """"""
        if pretty:
            return json.dumps(self.data, sort_keys=True, indent=4, separators=(',', ': '))
        else:
            return json.dumps(self.data)
522315
def structureOutput(fileUrl, fileName, searchFiles, format=True, space=40):
	""""""
	#First, remove the filename
	if format:
		splitUrls = fileUrl[1:].split('/')
		fileUrl = ""
		for splitUrl in splitUrls:
			# This is a gimmicky fix to make formatting consistent
			# Cemetech doesn't have /pub/ at the front of it's repo paths
			# Also, Omnimaga has a /files/ we need to get rid of similarly
			# This probably *should* be repo-dependent, but oh well
			if splitUrl != "" and (not "." in splitUrl) and (splitUrl != "pub" and splitUrl != "files"):
				fileUrl += splitUrl + '/'
			elif "." in splitUrl:
				archiveName = splitUrl

	#Now, format the output
	if searchFiles:
		fileName = archiveName
	pause = (space - len(fileUrl))
	output = fileUrl
	output += (" " * pause)
	output += fileName
	return output
934000
def _byteify(data):
    """"""

    # Unicode
    if isinstance(data, six.text_type):
        return data.encode("utf-8")

    # Members of lists
    if isinstance(data, list):
        return [_byteify(item) for item in data]

    # Members of dicts
    if isinstance(data, dict):
        return {
            _byteify(key): _byteify(value) for key, value in data.items()
        }

    # Anything else, return the original form
    return data
206633
def preprocess(
        self, nb: "NotebookNode", resources: dict
    ) -> Tuple["NotebookNode", dict]:
        """"""

        exam_num = resources["exam_num"]
        time = resources["time"]
        date = resources["date"]

        nb.cells.insert(0, new_markdown_cell(source="---"))
        nb.cells.insert(0, new_markdown_cell(source=""))
        nb.cells.insert(0, exam_instructions_cell)
        first_cell_source = (
            "# ME 2233: Thermodynamic Principles\n\n"
            f"# Exam {exam_num} - {time}\n\n# {date}"
        )
        nb.cells.insert(0, new_markdown_cell(source=first_cell_source))

        return nb, resources
822672
def _tool_to_dict(tool, records, remapped):
    
    requirements = _requirements_to_dict(tool.requirements + tool.hints)
    inputs = []
    outputs = []
    for inp in tool.tool["inputs"]:
        ready_inp, records = _input_to_dict(inp, records, remapped)
        inputs.append(ready_inp)
    for outp in tool.tool["outputs"]:
        ready_outp, records = _output_to_dict(outp, records)
        outputs.append(ready_outp)
    out = {"name": _id_to_name(tool.tool["id"]),
           "baseCommand": " ".join(tool.tool["baseCommand"]),
           "arguments": [_arg_to_dict(a, requirements) for a in tool.tool["arguments"]],
           "inputs": inputs,
           "outputs": outputs,
           "requirements": requirements,
           "stdin": None, "stdout": None}
    return out, records
810715
def _format_exe_info(py_len, exeinfo, format, indlevel):
    """"""
    ret = []
    ind = " " * indlevel * NIND if format.startswith("text") else ""
    if format == "markdown-list":
        for si in exeinfo:
            ret.append("  - `{0!s}`: {1!s}".format(si.filename, si.description))
    if format == "rest-list":
        for si in exeinfo:
            ret.append("* ``{0!s}``: {1!s}".format(si.filename, si.description))
    elif format == "markdown-table":
        mask = "%-{0:d}s | %s".format(py_len+2 )
        ret.append(mask % ("Script name", "Purpose"))
        ret.append("-" * (py_len + 3) + "|" + "-" * 10)
        for si in exeinfo:
            ret.append(mask % ("`{0!s}`".format(si.filename), si.description))
    elif format == "text":
        sbc = 1  # spaces between columns
        for si in exeinfo:
            ss = textwrap.wrap(si.description, 79 - py_len - sbc - indlevel*NIND)
            for i, s in enumerate(ss):
                if i == 0:
                    filecolumn = si.filename + " " + ("." * (py_len - len(si.filename)))
                else:
                    filecolumn = " " * (py_len + 1)

                ret.append("{}{}{}{}".format(ind, filecolumn, " "*sbc, s))
    ret.append("")
    return ret
671344
def _format_list(result):
    """"""

    if not result:
        return result

    if isinstance(result[0], dict):
        return _format_list_objects(result)

    table = Table(['value'])
    for item in result:
        table.add_row([iter_to_table(item)])
    return table
447680
def dumps(self, indent=1):
        

        str_keys_dict = OrderedDict({str(k): v for k, v in self.items()})
        for k, v in str_keys_dict.items():
            if isinstance(v, dict):
                str_keys_dict[k] = OrderedDict({str(k1): v1 for k1, v1 in v.items()})
                for k1, v1 in str_keys_dict[k].items():
                    if isinstance(v1, dict):
                        str_keys_dict[k][k1] = OrderedDict({str(k2): v2 for k2, v2 in v1.items()})
        return json.dumps(str_keys_dict, indent=indent)
525790
def build_data(self, plugin, attribute, stat):
        """"""
        line = ''

        if attribute is not None:
            line += '{}{}'.format(str(stat.get(attribute, self.na)),
                                  self.separator)
        else:
            if isinstance(stat, dict):
                for v in stat.values():
                    line += '{}{}'.format(str(v), self.separator)
            elif isinstance(stat, list):
                for i in stat:
                    if isinstance(i, dict) and 'key' in i:
                        for v in i.values():
                            line += '{}{}'.format(str(v), self.separator)
            else:
                line += '{}{}'.format(str(stat), self.separator)

        return line
230440
def format_results(self, raw_data, options):
        '''
        
        '''
        page_data = self.paginate_results(raw_data, options)
        results = {}
        meta = options.copy()
        meta['more'] = _('Show more results')
        if page_data and page_data.has_next():
            meta['next_page'] = page_data.next_page_number()
        if page_data and page_data.has_previous():
            meta['prev_page'] = page_data.previous_page_number()
        results['data'] = [self.format_item(item) for item in page_data.object_list]
        results['meta'] = meta
        return results
4648
def formatted(self):
        """"""
        return ' '.join(self.compact[i:i + 4] for i in range(0, len(self.compact), 4))
133145
def format(self, fmt):
        """"""
        _fmt_params = {
            'base': self.base,
            'bin': self.bin,
            'binary': self.binary,
            'bits': self.bits,
            'bytes': self.bytes,
            'power': self.power,
            'system': self.system,
            'unit': self.unit,
            'unit_plural': self.unit_plural,
            'unit_singular': self.unit_singular,
            'value': self.value
        }

        return fmt.format(**_fmt_params)
353688
def format_custom_fields(list_of_custom_fields):
        '''
            
        '''
        output_payload = {}
        if list_of_custom_fields:
            # custom_field: {"name": value}
            for custom_field in list_of_custom_fields:
                for key, value in custom_field.items():
                    output_payload["custom_fields[" + key + "]"] = value
        return output_payload
1017351
def combine_inputs_with_outputs(nb_source, nb_outputs, fmt=None):
    """"""

    output_code_cells = [cell for cell in nb_outputs.cells if cell.cell_type == 'code']
    output_other_cells = [cell for cell in nb_outputs.cells if cell.cell_type != 'code']

    fmt = long_form_one_format(fmt)
    text_repr = nb_source.metadata.get('jupytext', {}).get('text_representation', {})
    ext = fmt.get('extension') or text_repr.get('extension')
    format_name = fmt.get('format_name') or text_repr.get('format_name')

    nb_outputs_filtered_metadata = copy(nb_outputs.metadata)
    filter_metadata(nb_outputs_filtered_metadata,
                    nb_source.metadata.get('jupytext', {}).get('notebook_metadata_filter'),
                    _DEFAULT_NOTEBOOK_METADATA)

    for key in nb_outputs.metadata:
        if key not in nb_outputs_filtered_metadata:
            nb_source.metadata[key] = nb_outputs.metadata[key]

    source_is_md_version_one = ext in ['.md', '.Rmd'] and text_repr.get('format_version') == '1.0'
    if nb_source.metadata.get('jupytext', {}).get('formats') or ext in ['.md', '.Rmd']:
        nb_source.metadata.get('jupytext', {}).pop('text_representation', None)

    if not nb_source.metadata.get('jupytext', {}):
        nb_source.metadata.pop('jupytext', {})

    for cell in nb_source.cells:
        # Remove outputs to warranty that trust of returned notebook is that of second notebook
        if cell.cell_type == 'code':
            cell.execution_count = None
            cell.outputs = []

            for i, ocell in enumerate(output_code_cells):
                if same_content(cell.source, ocell.source):
                    # Fill outputs with that of second notebook
                    cell.execution_count = ocell.execution_count
                    cell.outputs = ocell.outputs

                    # Append cell metadata that was filtered
                    if format_name in ['bare', 'sphinx'] or source_is_md_version_one:
                        ocell_filtered_metadata = {}
                    else:
                        ocell_filtered_metadata = copy(ocell.metadata)
                        filter_metadata(ocell_filtered_metadata,
                                        nb_source.metadata.get('jupytext', {}).get('cell_metadata_filter'),
                                        _IGNORE_CELL_METADATA)

                    for key in ocell.metadata:
                        if key not in ocell_filtered_metadata and key not in _JUPYTEXT_CELL_METADATA:
                            cell.metadata[key] = ocell.metadata[key]

                    output_code_cells = output_code_cells[(i + 1):]
                    break
        else:
            for i, ocell in enumerate(output_other_cells):
                if cell.cell_type == ocell.cell_type and same_content(cell.source, ocell.source):
                    if format_name in ['spin', 'bare', 'sphinx'] or source_is_md_version_one:
                        ocell_filtered_metadata = {}
                    else:
                        ocell_filtered_metadata = copy(ocell.metadata)
                        filter_metadata(ocell_filtered_metadata,
                                        nb_source.metadata.get('jupytext', {}).get('cell_metadata_filter'),
                                        _IGNORE_CELL_METADATA)

                    for key in ocell.metadata:
                        if key not in ocell_filtered_metadata:
                            cell.metadata[key] = ocell.metadata[key]

                    output_other_cells = output_other_cells[(i + 1):]
                    break

    return nb_source
604047
def _SerializeEntries(entries):
  """"""

  output = []
  for python_format, wire_format, type_descriptor in entries:

    if wire_format is None or (python_format and
                               type_descriptor.IsDirty(python_format)):
      wire_format = type_descriptor.ConvertToWireFormat(python_format)

    precondition.AssertIterableType(wire_format, bytes)
    output.extend(wire_format)

  return b"".join(output)