def getCount(self, soup): if soup is not None: value = soup if hasattr(soup, 'text'): value = soup.text return long(value.replace(",", "").replace("%", "")) return 0
def getCount(self, soup): if soup is not None: value = soup if hasattr(soup, "text"): value = soup.text return long(value.replace(",", "").replace("%", "")) return 0
def compare(self, label, baseline, undertest, type): """ Compares 2 numbers to see if they are the same. The user may specify how to normalize mixed type comparisons via the type argument. """ self.label = label.strip() self.baseline = baseline self.undertest = undertest self.type = type.strip() # If we get a valid type, convert to that type and compare if self.type in self.supportedtypes: # Normalize for comparison if self.type == "int": self.baseline = int(self.baseline) self.undertest = int(self.undertest) elif self.type == "long": self.baseline = long(self.baseline) self.undertest = long(self.undertest) elif self.type == "float": self.baseline = float(self.baseline) self.undertest = float(self.undertest) else: self.baseline = complex(self.baseline) self.undertest = complex(self.undertest) # compare if self.baseline == self.undertest: self.result = {self.label: "Passed - numbers are the same"} else: self.result = {self.label: "Failed - " + str(self.baseline) + " expected: Got " + str(self.undertest)} TC.logger.log(self.result) return self.result else: self.result = {self.label: "Failed - " + self.type + " is not in list of supported types"} TC.logger.log(self.result) return self.result
def extract_spot_values(level2Packet, gap=40): powdata = level2Packet.getArray() spotvaluelist = spotvaluelist_dictionary() outputlist = list() #{} if len(powdata) > 0: for i in range(40, len(powdata), gap): # LogMessageWithByteArray("PowData", powdata[i:i+gap]) valuetype = level2Packet.getTwoByteLong(i + 1) idate = level2Packet.getFourByteLong(i + 4) t = time.localtime(long(idate)) if valuetype in spotvaluelist: spotvalue = spotvaluelist[valuetype] else: spotvalue = spotvaluelist["unknown"] valuetype = 0 if spotvalue.Units == "TEXT": value = powdata[i + 8:i + 8 + 14].decode("utf-8") elif spotvalue.Units == "hours": value = level2Packet.getFourByteDouble(i + 8) elif spotvalue.Units == "Wh": value = level2Packet.getFourByteDouble(i + 8) else: value = level2Packet.getThreeByteDouble(i + 8) if value is not None: value = value / spotvalue.Scale if i == 40: outputlist.append((0, time.strftime("%Y-%m-%d %H:%M:%S", t))) #print "{0} {1:04x} {2} '{3}' {4} {5}".format(time.asctime(t), valuetype, spotvalue.Description, value, spotvalue.Units, level2Packet.getThreeByteDouble(i + 8 + 4)) if value is None: value = 0.0 outputlist.append((valuetype, value)) return outputlist
def deserialize(self): if self.n and self.e: try: for param in self.longs: item = getattr(self, param) if not item or isinstance(item, six.integer_types): continue else: try: val = long(deser(item)) except Exception: raise else: setattr(self, param, val) lst = [self.n, self.e] if self.d: lst.append(self.d) if self.p: lst.append(self.p) if self.q: lst.append(self.q) self.key = RSA.construct(tuple(lst)) else: self.key = RSA.construct(lst) except ValueError as err: raise DeSerializationNotPossible("%s" % err) elif self.x5c: der_cert = base64.b64decode(self.x5c[0].encode("ascii")) if self.x5t: # verify the cert if not b64d(self.x5t.encode("ascii")) == hashlib.sha1(der_cert).digest(): raise DeSerializationNotPossible("The thumbprint ('x5t') does not match the certificate.") self.key = der2rsa(der_cert) self._split() if len(self.x5c) > 1: # verify chain pass else: raise DeSerializationNotPossible()
def get_scores(self, read): """ parses IMDB listing page and fetches relevant information :param read: read object :return: dict of popularity, best_rating, users, reviews, and external_reviews """ helper = ScrapeHelper(read) popularity = self.getPopularity(helper) popularity_change = self.meter_change(helper) score_div = helper.find_div_by_itemtype( 'http://schema.org/AggregateRating') rating = float( helper.find_by_itemprop('span', 'ratingValue', score_div).text.replace(",", "")) best_rating = int( helper.find_by_itemprop('span', 'bestRating', score_div).text.replace(",", "")) anchors = helper.find_all_anchors(score_div) users, reviews, external_reviews = '', '', '' for anchor in anchors: href = anchor.get('href').split('?')[0] count = long(self.getCount(anchor)) if href == 'ratings': users = count elif href == 'reviews': reviews = count elif href == 'externalreviews': external_reviews = count return { 'popularity': popularity, 'popularity_change': popularity_change, 'rating': rating, 'best_rating': best_rating, 'users': users, 'reviews': reviews, 'external_reviews': external_reviews }
def deserialize(self): if self.n and self.e: try: for param in self.longs: item = getattr(self, param) if not item or isinstance(item, six.integer_types): continue else: try: val = long(deser(item)) except Exception: raise else: setattr(self, param, val) lst = [self.n, self.e] if self.d: lst.append(self.d) if self.p: lst.append(self.p) if self.q: lst.append(self.q) self.key = RSA.construct(tuple(lst)) else: self.key = RSA.construct(lst) except ValueError as err: raise DeSerializationNotPossible("%s" % err) elif self.x5c: if self.x5t: # verify the cert pass cert = "\n".join([PREFIX, str(self.x5c[0]), POSTFIX]) self.key = import_rsa_key(cert) self._split() if len(self.x5c) > 1: # verify chain pass else: raise DeSerializationNotPossible()
def deserialize(self): if self.n and self.e: try: self.e = long(deser(self.e)) self.n = deser(self.n) if self.d: self.d = deser(self.d) self.key = RSA.construct((self.n, self.e, self.d)) else: self.key = RSA.construct((self.n, self.e)) except ValueError as err: raise DeSerializationNotPossible("%s" % err) elif self.x5c: if self.x5t: # verify the cert pass cert = "\n".join([PREFIX, str(self.x5c[0]), POSTFIX]) self.key = import_rsa_key(cert) self._split() if len(self.x5c) > 1: # verify chain pass else: raise DeSerializationNotPossible()
def test_long_equivalent_to_int(self): from __builtin__ import long # make source lintable on Python 3 DynamicField.validate_spec({'a': int}, {'a': long(9001)}) # no errors