Write out a Python dictionary made of up string keys, and values
        that are strings, signed integers, Decimal, datetime.datetime, or
        sub-dictionaries following the same constraints.
976603
def write_table(self, d):
        
        # HACK: encoding of AMQP tables is broken because it requires the
        # length of the /encoded/ data instead of the number of items. To
        # support streaming, fiddle with cursor position, rewinding to write
        # the real length of the data. Generally speaking, I'm not a fan of
        # the AMQP encoding scheme, it could be much faster.
        table_len_pos = len(self._output_buffer)
        self.write_long(0)
        table_data_pos = len(self._output_buffer)

        for key, value in d.iteritems():
            self._write_item(key, value)

        table_end_pos = len(self._output_buffer)
        table_len = table_end_pos - table_data_pos

        self.write_long_at(table_len, table_len_pos)
        return self
730861
def str_arg(d):
    """"""
    if not d:
        return None
    if isinstance(d, dict):
        if len(d) == 2 and d.get('type') == 'text' and 'value' in d:
            return str_arg(d['value'])
        if len(d) == 2 and d.get('type') == 'text' and 'subkey' in d:
            return ".%s" % d['subkey']
        if d.get('type') == 'module':
            return None
        return "{%s}" % str_args(d.items())
    if isinstance(d, list):
        if len(d) == 1:
            return str_arg(d[0])
        return "[%s]" % ", ".join(str_arg(elem) for elem in d)
    if isinstance(d, unicode):
        return '"%s"' % d

    return repr(d)
694678
def dict_encode(in_dict):
    """"""
    if _IS_PY2:
        out_dict = {}
        for k, v in list(in_dict.items()):
            if isinstance(v, unicode):
                v = v.encode('utf8')
            elif isinstance(v, str):
                # Must be encoded in UTF-8
                v.decode('utf8')
            out_dict[k] = v
        return out_dict
    else:
        raise NotImplementedError
163241
def make_dict(self, field_values):
        ''' 
        '''
        data_dict = {}
        for key, value, field_type, converter in zip(self.field_names, field_values, self.field_types, self.type_converters):
            try:
                # We have to deal with the '-' based on the field_type
                data_dict[key] = self.dash_mapper.get(field_type, '-') if value == '-' else converter(value)
            except ValueError as exc:
                print('Conversion Issue for key:{:s} value:{:s}\n{:s}'.format(key, str(value), str(exc)))
                data_dict[key] = value
                if self._strict:
                    raise exc

        return data_dict
700447
def write_attribute(key, values)
      set = read_attribute(key)
      if values.respond_to?(:to_str) && !set.single_value? && set.syntax_object && set.syntax_object.error("1\n1")
        values = values.split(/\r?\n/)
      elsif values == ''
        values = []
      end
      set.replace(values)
    end
190547
def encode_data(data):
    '''
    
    '''
    if isinstance(data, (six.string_types, bytes)):
        return encode_string(data)
    elif isinstance(data, (six.integer_types, bool, float)):
        return data
    elif data is None:
        return data
    elif isinstance(data, list):
        return [encode_data(x) for x in data]
    elif isinstance(data, dict):
        return {k: encode_data(v) for k, v in data.items()}
    else:
        raise ValueError('Cannot encode data of type %s' % type(data))
137870
def stringify_values(data):
    
    if not isinstance(data, dict):
        raise ValueError('Data must be dict. %r is passed' % data)

    values_dict = {}
    for key, value in data.items():
        items = []
        if isinstance(value, six.string_types):
            items.append(value)
        elif isinstance(value, Iterable):
            for v in value:
                # Convert to str int values
                if isinstance(v, int):
                    v = str(v)
                try:
                    item = six.u(v)
                except TypeError:
                    item = v
                items.append(item)
            value = ','.join(items)
        values_dict[key] = value
    return values_dict
171015
def pprint_int_dict(int_dict, indent=4, descending=False):
    
    sorted_tup = sorted(int_dict.items(), key=lambda x: x[1])
    if descending:
        sorted_tup.reverse()
    print('{')
    for tup in sorted_tup:
        print('{}{}: {}'.format(' '*indent, tup[0], tup[1]))
    print('}')
403986
def _write_dict(self, val, outstream):
        '''
        
        '''
        fields = val.keys()
        length = len(fields)
        self.write_dict_start(length, outstream)
        if length > 0:
            self.write_dict_field(fields[0], val[fields[0]], outstream)
            idx = 1
            while idx < length:
                name = fields[idx]
                value = val[fields[idx]]
                self.write_dict_field_separator(name, value, outstream)
                self.write_dict_field(name, value, outstream)
                idx += 1
        self.write_dict_end(length, outstream)
932207
def pretty(d, indent=0):
    
    for key, value in d.items():
        print('  ' * indent + str(key))
        if isinstance(value, dict):
            pretty(value, indent+1)
        else:
            sys.stderr.write('  ' * (indent+1) + str(value) + '\n')
571892
def text_dict_write(fpath, dict_):
    
    #dict_ = text_dict_read(fpath)
    #dict_[key] = val
    dict_text2 = util_str.repr4(dict_, strvals=False)
    if VERBOSE:
        print('[cache] ' + str(dict_text2))
    util_io.write_to(fpath, dict_text2)
803700
def serialize(dictionary):
    

    data = []
    for key, value in dictionary.items():
        data.append('{0}="{1}"'.format(key, value))
    return ', '.join(data)
1321010
def decode_dict_keys(d, coding="utf-8"):
    """"""
    assert compat.PY2
    res = {}
    for k, v in d.items():  #
        if type(k) is str:
            k = k.decode(coding)
        if type(v) is dict:
            v = decode_dict_keys(v, coding)
        res[k] = v
    return res
214615
def write_table(self, d):
        
        self._flushbits()
        table_data = AMQPWriter()
        for k, v in d.items():
            table_data.write_shortstr(k)
            if isinstance(v, basestring):
                if isinstance(v, unicode):
                    v = v.encode('utf-8')
                table_data.write(byte(83)) # 'S'
                table_data.write_longstr(v)
            elif isinstance(v, (int, long)):
                table_data.write(byte(73)) # 'I'
                table_data.write(pack('>i', v))
            elif isinstance(v, Decimal):
                table_data.write(byte(68)) # 'D'
                sign, digits, exponent = v.as_tuple()
                v = 0
                for d in digits:
                    v = (v * 10) + d
                if sign:
                    v = -v
                table_data.write_octet(-exponent)
                table_data.write(pack('>i', v))
            elif isinstance(v, datetime):
                table_data.write(byte(84)) # 'T'
                table_data.write_timestamp(v)
                ## FIXME: timezone ?
            elif isinstance(v, dict):
                table_data.write(byte(70)) # 'F'
                table_data.write_table(v)
            else:
                raise ValueError('%s not serializable in AMQP' % repr(v))
        table_data = table_data.getvalue()
        self.write_long(len(table_data))
        self.out.write(table_data)
527152
def str2dict(str_in):
    '''
    
    '''
    dict_out = safe_eval(str_in)
    if not isinstance(dict_out, dict):
        dict_out = None
    return dict_out
1068439
def validate(data):
    
    if not isinstance(data, dict):
        error('Data must be a dictionary.')
    for value in data.values():
        if not isinstance(value, basestring):
            error('Values must be strings.')
297347
def from_dict(self, values):
        
        for k in values.keys():
            setattr(self, k, values[k])