WSGI conform list of (header, value) tuples.
177121
def headerlist(self):
        
        if 'Content-Type' not in self.headers:
            self.headers.add_header('Content-Type', self.default_content_type)
        if self._cookies:
            for c in self._cookies.values():
                self.headers.add_header('Set-Cookie', c.OutputString())
        return self.headers.items()
935799
def values(self, values):
        
        if isinstance(values, dict):
            l = []
            for column in self._columns:
                l.append(values[column])
            self._values.append(tuple(l))
        else:
            self._values.append(values)
        return self
476813
def ensure_value(
        config: dict,
        name: Union[str, Tuple[str, ...]],
        mutable_config_list: List[str]):
    
    if not isinstance(name, tuple):
        path: Tuple[str, ...] = (name,)
    else:
        path = name
    for element in path[:-1]:
        config = config[element]

    value = config[path[-1]]
    if path[-1] in mutable_config_list:
        value = value['value']
    return value
150274
def select_header_accept(self, accepts):
        
        if not accepts:
            return

        accepts = list(map(lambda x: x.lower(), accepts))

        if 'application/json' in accepts:
            return 'application/json'
        else:
            return ', '.join(accepts)
219299
def parseAcceptHeader(value):
    
    chunks = [chunk.strip() for chunk in value.split(',')]
    accept = []
    for chunk in chunks:
        parts = [s.strip() for s in chunk.split(';')]

        mtype = parts.pop(0)
        if '/' not in mtype:
            # This is not a MIME type, so ignore the bad data
            continue

        main, sub = mtype.split('/', 1)

        for ext in parts:
            if '=' in ext:
                k, v = ext.split('=', 1)
                if k == 'q':
                    try:
                        q = float(v)
                        break
                    except ValueError:
                        # Ignore poorly formed q-values
                        pass
        else:
            q = 1.0

        accept.append((q, main, sub))

    accept.sort()
    accept.reverse()
    return [(main, sub, q) for (q, main, sub) in accept]
1226758
def flow_tuple(data):
    """"""
    src = net_utils.inet_to_str(data['packet'].get('src')) if data['packet'].get('src') else None
    dst = net_utils.inet_to_str(data['packet'].get('dst')) if data['packet'].get('dst') else None
    sport = data['transport'].get('sport') if data.get('transport') else None
    dport = data['transport'].get('dport') if data.get('transport') else None
    proto = data['transport'].get('type') if data.get('transport') else data['packet']['type']
    return (src, dst, sport, dport, proto)
693409
def compose_headers(self, req, headers=None, opt=None, as_dict=False):
        
        if headers is None:
            return list(req.header.items()) if not as_dict else req.header

        opt = opt or {}
        join_headers = opt.pop(BaseClient.join_headers, None)
        if as_dict and not join_headers:
            # pick the most efficient way for special case
            headers = dict(headers) if isinstance(headers, list) else headers
            headers.update(req.header)
            return headers

        # include Request.headers
        aggregated_headers = list(req.header.items())

        # include customized headers
        if isinstance(headers, list):
            aggregated_headers.extend(headers)
        elif isinstance(headers, dict):
            aggregated_headers.extend(headers.items())
        else:
            raise Exception('unknown type as header: {}'.format(str(type(headers))))

        if join_headers:
            joined = {}
            for h in aggregated_headers:
                key = h[0]
                if key in joined:
                    joined[key] = ','.join([joined[key], h[1]])
                else:
                    joined[key] = h[1]
            aggregated_headers = list(joined.items())

        return dict(aggregated_headers) if as_dict else aggregated_headers
1022351
def wsgi_wrap(app):
    '''
    
    '''
    @wraps(app)
    def wrapped(environ, start_response):
        status_headers = [None, None]
        def _start_response(status, headers):
            status_headers[:] = [status, headers]
        body = app(environ, _start_response)
        ret = body, status_headers[0], status_headers[1]
        return ret
    return wrapped
490544
def pack_tuple(self, values):
        
        assert isinstance(values, (tuple, list))
        cardinality = [struct_L.pack(len(values))]
        packed_items = [self.pack_field(v) for v in values]
        return b''.join(itertools.chain(cardinality, packed_items))
980329
def encode_tuple(data, encoding=None, errors='strict', keep=False,
                 preserve_dict_class=False):
    '''
    
    '''
    return tuple(
        encode_list(data, encoding, errors, keep, preserve_dict_class, True))
1278833
def cap_list(caps):
    """"""
    out = []
    caps = caps.split()

    for cap in caps:
        # turn modifier chars into named modifiers
        mods = []

        while len(cap) > 0 and cap[0] in cap_modifiers:
            attr = cap[0]
            cap = cap[1:]

            mods.append(cap_modifiers[attr])

        # either give string value or None if not specified
        if '=' in cap:
            cap, value = cap.rsplit('=', 1)
            if value and cap.casefold() in ['sasl']:
                value = CaseInsensitiveList(value.split(','))
        else:
            value = None

        out.append([cap, value, mods])

    return out
759857
def parse_http_accept_header(header):
    
    components = [item.strip() for item in header.split(',')]

    l = []
    for component in components:
        if ';' in component:
            subcomponents = [item.strip() for item in component.split(';')]
            l.append(
                (
                    subcomponents[0], # eg. 'text/html'
                    subcomponents[1][2:] # eg. 'q=0.9'
                )
            )
        else:
            l.append((component, '1'))

    l.sort(
        key = lambda i: i[1],
        reverse = True
    )

    content_types = []
    for i in l:
        content_types.append(i[0])

    return content_types
468090
def list_of_same(self, tup_tree, acceptable):
        

        k = kids(tup_tree)

        if not k:            # empty list, consistent with list_of_various
            return []

        a_child = name(k[0])
        if a_child not in acceptable:
            raise CIMXMLParseError(
                _format("Element {0!A} has invalid child element {1!A} "
                        "(allowed is a sequence of like elements from {2!A})",
                        name(tup_tree), a_child, acceptable),
                conn_id=self.conn_id)
        result = []
        for child in k:
            if name(child) != a_child:
                raise CIMXMLParseError(
                    _format("Element {0!A} has invalid child element {1!A} "
                            "(sequence must have like elements {2!A})",
                            name(tup_tree), name(child), a_child),
                    conn_id=self.conn_id)
            result.append(self.parse_any(child))

        return result
397824
def list_of_various(self, tup_tree, acceptable):
        

        result = []

        for child in kids(tup_tree):
            if name(child) not in acceptable:
                raise CIMXMLParseError(
                    _format("Element {0!A} has invalid child element {1!A} "
                            "(allowed are child elements {2!A})",
                            name(tup_tree), name(child), acceptable),
                    conn_id=self.conn_id)
            result.append(self.parse_any(child))

        return result
227023
def _SetValues(self, values):
    

    def _ToStr(value):
      """Convert individul list entries to string."""
      if isinstance(value, (list, tuple)):
        result = []
        for val in value:
          result.append(str(val))
        return result
      else:
        return str(value)

    # Row with identical header can be copied directly.
    if isinstance(values, Row):
      if self._keys != values.header:
        raise TypeError('Attempt to append row with mismatched header.')
      self._values = copy.deepcopy(values.values)

    elif isinstance(values, dict):
      for key in self._keys:
        if key not in values:
          raise TypeError('Dictionary key mismatch with row.')
      for key in self._keys:
        self[key] = _ToStr(values[key])

    elif isinstance(values, list) or isinstance(values, tuple):
      if len(values) != len(self._values):
        raise TypeError('Supplied list length != row length')
      for (index, value) in enumerate(values):
        self._values[index] = _ToStr(value)

    else:
      raise TypeError('Supplied argument must be Row, dict or list, not %s',
                      type(values))
385108
def as_tuple(self, value):
        """"""
        if isinstance(value, list):
            value = tuple(value)
        return value
172692
def _make_tuple(self, env):
    """"""
    t = runtime.Tuple(self, env, dict2tuple)
    # A tuple also provides its own schema spec
    schema = schema_spec_from_tuple(t)
    t.attach_schema(schema)
    return t