def iso2datetime(s): """ convert an ISO8601 formatted string to datetime """ if s == None or s == 'NULL' or s == 'null' or s == '': return None s = re.sub(r'\.[0-9]+', '', s) return datetime.fromtimestamp(iso2time(s))
def iso2datetime(s): """ convert an ISO8601 formatted string to datetime """ if s == None or s == "NULL" or s == "null" or s == "": return None s = re.sub(r"\.[0-9]+", "", s) return datetime.fromtimestamp(iso2time(s))
def getAccountInfo(self): """ return information about the account, if active """ acctid = self.__roomInstance.split("/")[0] resp = http_get("%sapp/account?account=%s&%s" % (self.__baseURL, acctid, self.__authToken), self.__authHeaders) if DEBUG: logging.info(resp) response = parseString(resp).documentElement check_status(response) info = response.getElementsByTagName('account-info')[0] ainfo = accountinfo() ainfo.userCount = int(getElementValue(info, 'user-count')) ainfo.bytesUp = int(getElementValue(info, 'total-bytes-up')) ainfo.bytesDown = int(getElementValue(info, 'total-bytes-down')) ainfo.messages = int(getElementValue(info, 'total-messages')) ainfo.peakUsers = int(getElementValue(info, 'peak-user-count')) ainfo.userTime = iso2time(getElementValue(info, 'total-time')) ainfo.dateCreated = getElementValueDate(info, 'date-created') ainfo.dateExpired = getElementValueDate(info, 'date-expired') return ainfo
def _really_load(self, f, filename, ignore_discard, ignore_expires): magic = f.readline() if not re.search(self.magic_re, magic): msg = ("%r does not look like a Set-Cookie3 (LWP) format " "file" % filename) raise LoadError(msg) now = time.time() header = "Set-Cookie3:" boolean_attrs = ("port_spec", "path_spec", "domain_dot", "secure", "discard") value_attrs = ("version", "port", "path", "domain", "expires", "comment", "commenturl") try: while 1: line = f.readline() if line == "": break if not line.startswith(header): continue line = line[len(header):].strip() for data in split_header_words([line]): name, value = data[0] standard = {} rest = {} for k in boolean_attrs: standard[k] = False for k, v in data[1:]: if k is not None: lc = k.lower() else: lc = None # don't lose case distinction for unknown fields if (lc in value_attrs) or (lc in boolean_attrs): k = lc if k in boolean_attrs: if v is None: v = True standard[k] = v elif k in value_attrs: standard[k] = v else: rest[k] = v h = standard.get expires = h("expires") discard = h("discard") if expires is not None: expires = iso2time(expires) if expires is None: discard = True domain = h("domain") domain_specified = domain.startswith(".") c = Cookie(h("version"), name, value, h("port"), h("port_spec"), domain, domain_specified, h("domain_dot"), h("path"), h("path_spec"), h("secure"), expires, discard, h("comment"), h("commenturl"), rest) if not ignore_discard and c.discard: continue if not ignore_expires and c.is_expired(now): continue self.set_cookie(c) except IOError: raise except Exception: _warn_unhandled_exception() raise LoadError("invalid Set-Cookie3 format file %r: %r" % (filename, line))
def _really_load(self, f, filename, ignore_discard, ignore_expires): magic = f.readline() if not re.search(self.magic_re, magic): msg = '%r does not look like a Set-Cookie3 (LWP) format file' % filename raise LoadError(msg) now = time.time() header = 'Set-Cookie3:' boolean_attrs = ('port_spec', 'path_spec', 'domain_dot', 'secure', 'discard') value_attrs = ('version', 'port', 'path', 'domain', 'expires', 'comment', 'commenturl') try: while 1: line = f.readline() if line == '': break if not line.startswith(header): continue line = line[len(header):].strip() for data in split_header_words([line]): name, value = data[0] standard = {} rest = {} for k in boolean_attrs: standard[k] = False for k, v in data[1:]: if k is not None: lc = k.lower() else: lc = None if lc in value_attrs or lc in boolean_attrs: k = lc if k in boolean_attrs: if v is None: v = True standard[k] = v elif k in value_attrs: standard[k] = v else: rest[k] = v h = standard.get expires = h('expires') discard = h('discard') if expires is not None: expires = iso2time(expires) if expires is None: discard = True domain = h('domain') domain_specified = domain.startswith('.') c = Cookie(h('version'), name, value, h('port'), h('port_spec'), domain, domain_specified, h('domain_dot'), h('path'), h('path_spec'), h('secure'), expires, discard, h('comment'), h('commenturl'), rest) if not ignore_discard and c.discard: continue if not ignore_expires and c.is_expired(now): continue self.set_cookie(c) except IOError: raise except Exception: _warn_unhandled_exception() raise LoadError('invalid Set-Cookie3 format file %r: %r' % (filename, line)) return