def check_data(self, res, stamp=None, id=None, begin=None, end=None): """Check a data and add it cache.""" flag_got = False flag_spam = False count = 0 for i in res: count += 1 r = Record(datfile=self.datfile) parse_ok = r.parse(i) if ( parse_ok and ((stamp is None) or (r["stamp"] == str(stamp))) and ((not id) or (r["id"] == id)) and ((begin is None) or (begin <= r.stamp)) and ((end is None) or (r.stamp <= end)) and r.md5check() ): flag_got = True if (len(i) > config.record_limit * 1024) or spam.check(i): sys.stderr.write("Warning: %s/%s: too large or spam record.\n" % (self.datfile, r.idstr)) self.add_data(r, False) r.remove() flag_spam = True else: self.add_data(r) else: if stamp is not None: str_stamp = "/%s" % stamp elif "stamp" in r: str_stamp = "/%s" % r["stamp"] else: str_stamp = "" sys.stderr.write("Warning: %s%s: broken record.\n" % (self.datfile, str_stamp)) r.free() return count, flag_got, flag_spam
def post_comment(thread_key, name, mail, body, passwd, tag=None): """Post article.""" stamp = int(time.time()) recbody = {} if body != '': recbody['body'] = gateway.CGI.escape(None, body) if name != '': recbody['name'] = gateway.CGI.escape(None, name) if mail != '': recbody['mail'] = gateway.CGI.escape(None, mail) c = cache.Cache(thread_key) rec = cache.Record(datfile=c.datfile) id = rec.build(stamp, recbody, passwd=passwd) if spam.check(rec.recstr): raise SpamError() # utils.log('post %s/%d_%s' % (c.datfile, stamp, id)) c.add_data(rec) c.sync_status() if tag: utils.save_tag(c, tag) queue = updatequeue.UpdateQueue() queue.append(c.datfile, stamp, id, None) queue.start()
def check_data(self, res, stamp=None, id=None, begin=None, end=None): """Check a data and add it cache.""" flag_got = False flag_spam = False count = 0 for i in res: count += 1 r = Record(datfile=self.datfile) parse_ok = r.parse(i) if parse_ok and \ ((stamp is None) or (r['stamp'] == str(stamp))) and \ ((not id) or (r['id'] == id)) and \ ((begin is None) or (begin <= r.stamp)) and \ ((end is None) or (r.stamp <= end)) and \ r.md5check(): flag_got = True if (len(i) > config.record_limit * 1024) or spam.check(i): sys.stderr.write('Warning: %s/%s: too large or spam record.\n' % (self.datfile, r.idstr)) self.add_data(r, False) r.remove() flag_spam = True else: self.add_data(r) else: if stamp is not None: str_stamp = '/%s' % stamp elif 'stamp' in r: str_stamp = '/%s' % r['stamp'] else: str_stamp = '' sys.stderr.write("Warning: %s%s: broken record.\n" % (self.datfile, str_stamp)) r.free() return count, flag_got, flag_spam
def post_comment(env, thread_key, name, mail, body, passwd, tag=None): """Post article.""" if config.server_name: dat_host = config.server_name else: host = env['HTTP_HOST'] dat_host = re.sub(r':\d+', ':' + str(config.dat_port), host) p = re.compile(r'https?://' + dat_host + '/test/read.cgi/2ch(?:_[0-9A-Z]+)?/([0-9]+)/') for x in p.finditer(body): try: file = keylib.get_filekey(x.group(1)) body = body.replace(x.group(0), '[[' + title.file_decode(file) + ']]') except keylib.DatkeyNotFound: pass stamp = int(time.time()) recbody = {} if body != '': recbody['body'] = gateway.CGI.escape(None, body) if name != '': recbody['name'] = gateway.CGI.escape(None, name) if mail != '': recbody['mail'] = gateway.CGI.escape(None, mail) c = cache.Cache(thread_key) rec = cache.Record(datfile=c.datfile) id = rec.build(stamp, recbody, passwd=passwd) if spam.check(rec.recstr): raise SpamError() # utils.log('post %s/%d_%s' % (c.datfile, stamp, id)) c.add_data(rec) c.sync_status() if tag: utils.save_tag(c, tag) queue = updatequeue.UpdateQueue() queue.append(c.datfile, stamp, id, None) queue.start()
def post_comment(env, thread_key, name, mail, body, passwd, tag=None): """Post article.""" if config.server_name: dat_host = config.server_name else: host = env['HTTP_HOST'] dat_host = re.sub(r':\d+', ':' + str(config.dat_port), host) p = re.compile(r'https?://' + dat_host + '/test/read.cgi/2ch(?:_[0-9A-Z]+)?/([0-9]+)/') for x in p.finditer(body): try: file = keylib.get_filekey(x.group(1)) body = body.replace(x.group(0),'[[' + title.file_decode(file) + ']]') except keylib.DatkeyNotFound: pass stamp = int(time.time()) recbody = {} if body != '': recbody['body'] = gateway.CGI.escape(None, body) if name != '': recbody['name'] = gateway.CGI.escape(None, name) if mail != '': recbody['mail'] = gateway.CGI.escape(None, mail) c = cache.Cache(thread_key) rec = cache.Record(datfile=c.datfile) id = rec.build(stamp, recbody, passwd=passwd) if spam.check(rec.recstr): raise SpamError() # utils.log('post %s/%d_%s' % (c.datfile, stamp, id)) c.add_data(rec) c.sync_status() if tag: utils.save_tag(c, tag) queue = updatequeue.UpdateQueue() queue.append(c.datfile, stamp, id, None) queue.start()