def listado(id = 0, nombre = ""): if (id > 0): return bd.findById(ENTITY, id) elif (not util.isBlank(nombre)): return bd.find("SELECT * FROM %s WHERE nombre LIKE '%s' ORDER BY nombre ASC " % (ENTITY, "%" + nombre + "%")) else: return bd.findAll(ENTITY, "nombre")
def add(self,text,user_id,post_id): errs = [] if util.isBlank(text): errs.append('Comment cannot be blank.') if len(errs) < 1: return Comment.manager.create( text = text, user_id = user_id,#user who posted post_id = post_id #post it belongs to ) else: return errs
def add(self,text,user_id,profile_id): errs = [] if util.isBlank(text): errs.append('Post cannot be blank.') if len(errs) < 1: return Post.manager.create( text = text, user_id = user_id, profile_id = profile_id ) else: return errs
def xpath(self, path): if ( self.body is None or isBlank(path) ): #this means this is not a sdp. may be other body like xml return self.str if ( self.body is None): return None (key, index) = parseIndex(path) if key in self.dict: try: return self.dict[key][index] except: return None else: return None
def readDescriptors(self, in_stream): line = in_stream.readline() while line and (util.isComment(line) or util.isBlank(line)): line = in_stream.readline() if line and not line.strip() == '': flds = line.strip().split("\t") self.filename = flds[0] self.invert = (flds[1].lower() in ['1','y','t']) self.experiment = flds[2] res = os.path.isfile(os.path.expanduser(self.filename)) if not res: print "# Evidence file not found: {me.filename}".format(me=self) else: res = False return res
def __init__(self, body): self.str = body self.body = None if (isBlank(body)): return self.dict = {} # map from key to list of attribute lines with same key try: self.body = SDPParser.Body.parseString(body).body except: #print "kyu parse SDP failed. body is:\n%s" % body return for a in self.body: if(a.key in self.dict): self.dict[a.key].append(a.value) else: self.dict[a.key] = [a.value]
def parseHeaders(s): mylog("parse Headers\n") result = {} lines = s.splitlines(); for line in lines: if isBlank(line): continue if line.startswith("Message:"): continue #example: #version (1B) = 0x01 - 1 try: (name, sep, value) = line.partition("=") if (sep == "="): r = re.match("\s*(\w+)\s*\(\w+\)", name) name = r.group(1) result[name] = Header(name, value.strip()) except: raise DiamParseError("Parse header error: %s", line) mylog(result) return result