def end_element(self, name): # character data strip d = self.cdata.strip(" \n") self.cdata = unicode() # pop mode and set next mode mode = self.mode.pop() self.nmode = mode if d: # d = int(d) \ # if d.isdigit() and name[-2:] == "id" else d if d == "true": d = True elif d == "false": d = False if mode: # for ids self.data.append(d) else: # string element self.data.append([name, d]) elif self.name and name == self.name[-1]: # empty element self.data.append([name, None]) else: elements = [] while self.name.pop() != name: elements.append(self.data.pop()) self.name.append(name) if mode: if name == "status": self.data.append(twstatus(elements)) elif name == "user": self.data.append(twuser(elements)) else: # array element self.data.append(dict(elements)) else: if isinstance(elements[0], (dict, twstatus, twuser)): # array parent self.data.append((name, elements)) else: # others if name == "status": self.data.append((name, twstatus(elements))) elif name == "user": self.data.append((name, twuser(elements))) elif name == "ids": # for ids self.data.append((name, tuple(elements))) else: self.data.append((name, dict(elements)))
def end_element(self, name): # character data strip d = self.cdata.strip(" \n") self.cdata = unicode() # pop mode and set next mode mode = self.mode.pop() self.nmode = mode if d: #d = int(d) \ # if d.isdigit() and name[-2:] == "id" else d if d == "true": d = True elif d == "false": d = False if mode: # for ids self.data.append(d) else: # string element self.data.append([name, d]) elif self.name and name == self.name[-1]: # empty element self.data.append([name, None]) else: elements = [] while self.name.pop() != name: elements.append(self.data.pop()) self.name.append(name) if mode: if name == "status": self.data.append(twstatus(elements)) elif name == "user": self.data.append(twuser(elements)) else: # array element self.data.append(dict(elements)) else: if isinstance(elements[0], (dict, twstatus, twuser)): # array parent self.data.append((name, elements)) else: # others if name == "status": self.data.append((name, twstatus(elements))) elif name == "user": self.data.append((name, twuser(elements))) elif name == "ids": # for ids self.data.append((name, tuple(elements))) else: self.data.append((name, dict(elements)))
def __init__(self, d): status = dict(d) self.data = status if "delete" in status: return self.created_at = twittertime(status["created_at"]) for i in ("id", "in_reply_to_status_id", "in_reply_to_user_id"): setattr(self, i, int(status[i]) \ if status[i] != None else None) for i in ("text", "source", "in_reply_to_screen_name"): setattr(self, i, unicode(status[i]) \ if status[i] != None else None) self.source_name = twittersource(self.source) for i in ("favorited", "truncated"): setattr(self, i, status[i]) if "user" in status.keys(): self.user = user.twuser(status["user"]) if "retweeted_status" in status.keys(): self.retweeted_status = twstatus(status["retweeted_status"]) else: self.retweeted_status = None