Decorator for stream outputs that checks the format of the outputs after modifiers have been applied
    :param expected_formats: The expected output formats
    :type expected_formats: tuple, set
    :return: the decorator
18193
def check_output_format(expected_formats):
    
    def output_format_decorator(func):
        def func_wrapper(*args, **kwargs):
            self = args[0]
            if self.output_format not in expected_formats:
                raise ValueError("expected output format {}, got {}".format('doc_gen', self.output_format))
            return func(*args, **kwargs)
        return func_wrapper
    return output_format_decorator
328104
def check_format(actual_file,    # type: Union[Dict[Text, Any], List, Text]
                 input_formats,  # type: Union[List[Text], Text]
                 ontology        # type: Optional[Graph]
                ):  # type: (...) -> None
    
    for afile in aslist(actual_file):
        if not afile:
            continue
        if "format" not in afile:
            raise validate.ValidationException(
                u"File has no 'format' defined: {}".format(
                    json_dumps(afile, indent=4)))
        for inpf in aslist(input_formats):
            if afile["format"] == inpf or \
                    formatSubclassOf(afile["format"], inpf, ontology, set()):
                return
        raise validate.ValidationException(
            u"File has an incompatible format: {}".format(
                json_dumps(afile, indent=4)))
673558
def output_format_module(self, packages, esc_path=False):
        

        def create_ordered_list(packages_):
            """
            Recursive for package.packages
            """
            list_ = []
            for _pkg_name in packages_:
                _pkg = packages_[_pkg_name]
                if _pkg and _pkg.packages:
                    list_.extend(create_ordered_list(_pkg.packages))
                if _pkg:
                    _pkg_params = _pkg.get_params(self._columns, True)
                    _res_item = {}
                    for item in self._output_config['columns']:
                        name = item['name'].format(OutFormat(item['column']))
                        value = _pkg_params.get(item['column'], '')
                        if not isinstance(value, (list, dict, tuple)):
                            try:
                                value = item['value'].format(
                                    OutFormat(value, (item['column'] == 'path') if esc_path else False))
                            except Exception:
                                value = ''
                        # TODO: implement this:
                        # if not value:
                        #     try:
                        #         value = item['value'].format(OutFormat(_pkg.get_params('', True)))
                        #     except Exception as e:
                        #         pass
                        _res_item[name] = value
                    list_.append(_res_item)
            return list_

        result_list = create_ordered_list(packages, )

        if self._output_config['type'] == LIST:
            return result_list

        result = OrderedDict()
        for item in result_list:
            # TODO: Error handling
            name = item[self._output_config['key']]
            if self._output_config['value']:
                value = item[self._output_config['value']]
            else:
                value = OrderedDict([(k, v) for k, v in item.items() if k != self._output_config['key']])

            result[name] = value

        return result
440212
def _output_format(self, out, fmt_j=None, fmt_p=None):
        
        if self.output_format == 'pandas':
            if fmt_p is not None:
                return fmt_p(out)
            else:
                return self._convert_output(out)
        if fmt_j:
            return fmt_j(out)
        return out
290697
def _expect_token(self, expected):
        

        item = self._lexer.get_token()

        if not item:
            raise ParseError(u'Unexpected end of file')

        else:
            line_no, token = item

        if token != expected:
            raise ParseError(u"Unexpected token '{0}', "
                             u"expecting '{1}' on line {2}"
                             .format(common.from_utf8(token.strip()), expected,
                                     line_no))
702550
def ensure_utf8_streams():
        

        def ensure_utf8_stream(stream):
            if not isinstance(stream, io.StringIO):
                stream = getwriter("utf-8")(getattr(stream, "buffer", stream))
                stream.encoding = "utf-8"
            return stream

        sys.stdout, sys.stderr = (ensure_utf8_stream(s)
                                  for s in (sys.stdout, sys.stderr))
1066005
def decorator_info(f_name, expected, actual, flag):
    
    format = lambda types: ', '.join([str(t).split("'")[1] for t in types])
    expected, actual = format(expected), format(actual)
    msg = "'{}' method ".format(f_name) \
          + ("accepts", "returns")[flag] + " ({}), but ".format(expected) \
          + ("was given", "result is")[flag] + " ({})".format(actual)

    return msg
1013190
def output(data, **kwargs):  # pylint: disable=unused-argument
    '''
    
    '''

    params = {}
    if 'output_indent' not in __opts__:
        # default indentation
        params.update(default_flow_style=False)
    elif __opts__['output_indent'] >= 0:
        # custom indent
        params.update(default_flow_style=False,
                      indent=__opts__['output_indent'])
    else:  # no indentation
        params.update(default_flow_style=True,
                      indent=0)
    try:
        return salt.utils.yaml.safe_dump(data, **params)
    except Exception as exc:
        import pprint
        log.exception(
            'Exception %s encountered when trying to serialize %s',
            exc, pprint.pformat(data)
        )
377575
def format(
        self,
        format_string,
        module=None,
        param_dict=None,
        force_composite=False,
        attr_getter=None,
    ):
        
        # fix python 2 unicode issues
        if python2 and isinstance(format_string, str):
            format_string = format_string.decode("utf-8")

        if param_dict is None:
            param_dict = {}

        # if the processed format string is not in the cache then create it.
        if format_string not in self.block_cache:
            self.build_block(format_string)

        first_block = self.block_cache[format_string]

        def get_parameter(key):
            """
            function that finds and returns the value for a placeholder.
            """
            if key in param_dict:
                # was a supplied parameter
                param = param_dict.get(key)
            elif module and hasattr(module, key):
                param = getattr(module, key)
                if hasattr(param, "__call__"):
                    # we don't allow module methods
                    raise Exception()
            elif attr_getter:
                # get value from attr_getter function
                try:
                    param = attr_getter(key)
                except:  # noqa e722
                    raise Exception()
            else:
                raise Exception()
            if isinstance(param, Composite):
                if param.text():
                    param = param.copy()
                else:
                    param = u""
            elif python2 and isinstance(param, str):
                param = param.decode("utf-8")
            return param

        # render our processed format
        valid, output = first_block.render(get_parameter, module)

        # clean things up a little
        if isinstance(output, list):
            output = Composite(output)
        if not output:
            if force_composite:
                output = Composite()
            else:
                output = ""

        return output
978459
def validate_format(self, **kwargs):
        
        args = dict(
            dict_type=self._dict,
            allow_no_value=self._allow_no_value,
            inline_comment_prefixes=self._inline_comment_prefixes,
            strict=self._strict,
            empty_lines_in_values=self._empty_lines_in_values
        )
        args.update(kwargs)
        parser = ConfigParser(**args)
        updated_cfg = str(self)
        parser.read_string(updated_cfg)
1343313
def validate_header(self, channeldir, filename, expected_header):
        
        expected = set(expected_header)
        csv_filename = get_metadata_file_path(channeldir, filename)
        csv_lines = _read_csv_lines(csv_filename)
        dict_reader = csv.DictReader(csv_lines)
        actual = set(dict_reader.fieldnames)
        if not actual == expected:
            raise ValueError('Unexpected CSV file header in ' + csv_filename \
                             + ' Expected header:' + str(expected))
92418
def new_encoded_stream(args, stream):
    ''''''
    if args.ascii_print:
        return wpull.util.ASCIIStreamWriter(stream)
    else:
        return stream
756756
def _compare_expected(expected, output, sess, onnx, decimal=5, onnx_shape=None, **kwargs):
    
    tested = 0
    if isinstance(expected, list):
        if isinstance(output, list):
            onnx_shapes = [_.shape for _ in sess.get_outputs()]
            if 'Out0' in kwargs:
                expected = expected[:1]
                output = output[:1]
                del kwargs['Out0']
            if 'Reshape' in kwargs:
                del kwargs['Reshape']
                output = numpy.hstack(output).ravel()
                output = output.reshape((len(expected),
                                         len(output.ravel()) // len(expected)))
            if len(expected) != len(output):
                raise OnnxRuntimeAssertionError("Unexpected number of outputs '{0}', expected={1}, got={2}".format(onnx, len(expected), len(output)))
            for exp, out, osh in zip(expected, output, onnx_shapes):
                _compare_expected(exp, out, sess, onnx, decimal=decimal, onnx_shape=osh, **kwargs)
                tested += 1
        else:
            raise OnnxRuntimeAssertionError("Type mismatch for '{0}', output type is {1}".format(onnx, type(output)))
    elif isinstance(expected, dict):
        if not isinstance(output, dict):
            raise OnnxRuntimeAssertionError("Type mismatch for '{0}'".format(onnx))
        for k, v in output.items():
            if k not in expected:
                continue
            msg = compare_outputs(expected[k], v, decimal=decimal, **kwargs)
            if msg:
                raise OnnxRuntimeAssertionError("Unexpected output '{0}' in model '{1}'\n{2}".format(k, onnx, msg))
            tested += 1
    elif isinstance(expected, numpy.ndarray):
        if isinstance(output, list):
            if expected.shape[0] == len(output) and isinstance(output[0], dict):
                import pandas
                output = pandas.DataFrame(output)
                output = output[list(sorted(output.columns))]
                output = output.values
        if isinstance(output, (dict, list)):
            if len(output) != 1:
                ex = str(output)
                if len(ex) > 70:
                    ex = ex[:70] + "..."
                raise OnnxRuntimeAssertionError("More than one output when 1 is expected for onnx '{0}'\n{1}".format(onnx, ex))
            output = output[-1]
        if not isinstance(output, numpy.ndarray):
            raise OnnxRuntimeAssertionError("output must be an array for onnx '{0}' not {1}".format(onnx, type(output)))
        if onnx_shape is not None:
            if len(onnx_shape) == 2:
                cols = onnx_shape[1]
                ecols = output.shape[1] if len(output.shape) == 2 else 1
                if cols != ecols:
                    raise OnnxRuntimeAssertionError("Unexpected onnx shape {0} != {1} for onnx '{2}'".format(
                                onnx_shape, output.shape, onnx))
        msg = compare_outputs(expected, output, decimal=decimal, **kwargs)
        if isinstance(msg, ExpectedAssertionError):
            raise msg
        if msg:
            raise OnnxRuntimeAssertionError("Unexpected output in model '{0}'\n{1}".format(onnx, msg))
        tested += 1
    else:
        from scipy.sparse.csr import csr_matrix
        if isinstance(expected, csr_matrix):
            # DictVectorizer
            one_array = numpy.array(output)
            msg = compare_outputs(expected.todense(), one_array, decimal=decimal, **kwargs)
            if msg:
                raise OnnxRuntimeAssertionError("Unexpected output in model '{0}'\n{1}".format(onnx, msg))
            tested += 1
        else:
            raise OnnxRuntimeAssertionError("Unexpected type for expected output ({1}) and onnx '{0}'".format(onnx, type(expected)))
    if tested ==0:
        raise OnnxRuntimeAssertionError("No test for onnx '{0}'".format(onnx))
889748
def make_formatters(self):
        
        return [self.make_formatter(inner_w, spec['padding'], spec['align'],
                                    spec['overflow'])
                for spec, inner_w in zip(self.colspec, self.widths)]
471639
def dump(self, format=None, **kwargs):
        
        formatter = Formatters.get(format, None)
        if not format:
            return self.display()
        elif not formatter:
            raise FormattingException('Formatter %s not available' % format)
        else:
            return formatter(self, **kwargs)
340078
def set_sub_stream_format(self, format, callback=None):
        '''
        
        '''
        params = {'format': format}
        return self.execute_command('setSubStreamFormat',
                                        params, callback=callback)
1048635
def GetFormatSpecification(cls):
    
    format_specification = specification.FormatSpecification(cls.NAME)
    format_specification.AddNewSignature(b'ElfFile\x00', offset=0)
    return format_specification