def clean_sources(p): src = p.sources[:] p.sources = [] for s in src: if s: if isinstance(s, tumblr.Blog): t = s else: t = tumblr.get(s) if not t: t = tumblr.create(s) t.assign_img(p)