def _is_label_data_valid(self, labels, max_classes_num=15, min_images_num=40, max_images_num=2000): ''' labels len should >= 2 and should be ascii letters, no Chinese or special words images number in every label should > 40 ''' if len(labels) <= 1: err_msg = "datasets no enough class or directory error" return False, err_msg if len(labels) > max_classes_num: err_msg = "datasets too much class or directory error, limit:{} classses".format( max_classes_num) return False, err_msg print(labels, "---------") for label in labels: if not isascii(label): return False, "class name(label) should not contain special letters" # check image number files = os.listdir(os.path.join(self.datasets_dir, label)) if len(files) < min_images_num: return False, "no enough train images in one class, should > {}".format( min_images_num) if len(files) > max_images_num: return False, "too many train images in one class, should < {}".format( max_images_num) return True, ""
def tryRead(self, binaryToo): if not self.port: return 0 numRead = 0 with self.portLock: self.bufferLock.acquire() try: while self.port.inWaiting(): c = self.port.read(1) # save to file if required (raw data) if configuration.c.getCfgValue("saveToFilename") \ and not configuration.c.getCfgValue("saveProcessedData"): filename = os.path.join(configuration.c.getCfgValue("dataDirectory"), self.moteDescription.getPort(), configuration.c.getCfgValue("saveToFilename")) with open(filename, "a") as f: f.write(c) f.close() # add to the local buffer if binaryToo or utils.isascii(c): self.buffer += c numRead += 1 except Exception as e: print("\nserial read exception:\t" + str(e)) self.port.close() self.port = None finally: self.bufferLock.release() return numRead
def parse_init(line): try: method, url, protocol = string.split(line) except ValueError: return None httpversion = parse_http_protocol(protocol) if not httpversion: return None if not utils.isascii(method): return None return method, url, httpversion
def parse_init_http(line): """ Returns (method, url, httpversion) """ v = parse_init(line) if not v: return None method, url, httpversion = v if not utils.isascii(url): return None if not (url.startswith("/") or url == "*"): return None return method, url, httpversion
def _is_labels_valid(self, labels): ''' labels len should >= 1 and should be ascii letters, no Chinese or special words ''' if len(labels) < 1: err_msg = "labels error: datasets no enough class" return False, err_msg if len(labels) > self.config_max_classes_limit: err_msg = "labels error: too much classes, now {}, but only support {}".format( len(labels), self.config_max_classes_limit) return False, err_msg for label in labels: if not isascii(label): return False, "labels error: class name(label) should not contain special letters" return True, "ok"
def parse_url(url): """ Returns a (scheme, host, port, path) tuple, or None on error. Checks that: port is an integer 0-65535 host is a valid IDNA-encoded hostname with no null-bytes path is valid ASCII """ try: scheme, netloc, path, params, query, fragment = urlparse.urlparse(url) except ValueError: return None if not scheme: return None if ':' in netloc: host, port = string.rsplit(netloc, ':', maxsplit=1) try: port = int(port) except ValueError: return None else: host = netloc if scheme == "https": port = 443 else: port = 80 path = urlparse.urlunparse(('', '', path, params, query, fragment)) if not path.startswith("/"): path = "/" + path if not _is_valid_host(host): return None if not utils.isascii(path): return None if not _is_valid_port(port): return None return scheme, host, port, path