def __init__(self, identifier, info, status_id, titles, year, files=None, plot=None, tagline=None): self._attr_from_init(locals()) #print self.__class__.__bases__ try: self.info = (self.info if isinstance(self.info, Info) else Info(**self.info)) except TypeError, e: print e print len(self.info.keys()), identifier d, a = func_default_dict(Info.__init__) print [ x for x in self.info.keys() if x not in a.args ] print [ x for x in a.args[1:] if not d.has_key(x) and not self.info.has_key(x) ] print identifier, self.info.keys() self.files = [ x if isinstance(x, File) else File(**x) for x in self.files ] self.titles = [ x if isinstance(x, Title) else Title(**x) for x in self.titles ] @property def default_title(self): if not self._default_title: for title in self.titles: if title.default: self._default_title=title.title break return self._default_title
def _attr_from_init(self,local=None): """ The Couch Potato API has several different result structures. This allows rapid prototypid of objects based off the keys of the dictionary structures. Some of these are appropriate for later serialization via YAML in config files. Typical usage class foo(CouchPotatoDict): bar=1 baz=2 quf=0 mung=None def __init__(self, bar, baz, quf=None, mung=None): self._attr_from_init(locals()) if not isinstance(Mung, self.mung): self.mung=Mung(**self.mung) """ if not local: local = {} defaults, argspec = func_default_dict(self.__init__) for arg in argspec.args[1:]: if local.has_key(arg) and local[arg] != defaults.get(arg,None): if local[arg] != getattr(self, arg, None): setattr(self, arg, local[arg])
def _make_query(cls, local): default_dict, argspec = func_default_dict(cls.make_query) query = tuple( (cls._unicode_fiddle(arg), cls._unicode_fiddle(local[arg])) for arg in argspec.args[1:] if (local.has_key(arg) and local[arg] != default_dict.get(arg, None))) return query