def wrap(self, val): if is_atomic(val): return val elif is_listy(val): return DibListProxy(val) elif is_dicty(val): return DibWrap(val) else: return val
def _dibjectify(ob): """ extracts whatever looks like a concoction of dicts, lists and atomic types in ob and recreates them as dicts, lists and atomic types dicts come back as the dict subclass Dibject which allows keys to be accessed as attributes like feedparser. """ if ob is None: return None if is_atomic(ob): if isinstance(ob, UnicodeType): return UnicodeType(ob) elif isinstance(ob, StringType): return StringType(ob) elif isinstance(ob, IntType): return IntType(ob) elif isinstance(ob, FloatType): return FloatType(ob) elif isinstance(ob, LongType): return LongType(ob) else: log.debug('Skipping "%s" of atomic type %s' % (ob, ob.__class__)) return None elif is_dicty(ob): d = Dibject() for (k, v) in ob.items(): fk = dibjectify(k) fv = dibjectify(v) if fv is not None and fk is not None: d[fk] = fv return d elif is_listy(ob): l = [] for x in ob: fv = dibjectify(x) if fv is not None: l.append(fv) return l else: log.debug('Skipping "%s" of unserializable type %s' % (ob, ob.__class__)) return None
def make_object_uri(base_uri, cfg): """ takes a base uri and a dictionary of limited form and produces an object uri. base_uri and keys should be strings, values should be unicodes, or lists of unicodes. strings or other types that have __str__ may be used but they must be in utf-8 encoding. """ qargs = [] for k, vs in cfg.items(): okey = _to_utf8(k) if is_atomic(vs): qargs.append( (okey, _to_utf8(vs)) ) elif is_listy(vs): for v in vs: qargs.append( (okey, _to_utf8(v)) ) uri = base_uri + "?" + urlencode(qargs) return normalize_object_uri(uri)