def query(status=None, offset=0, limit=20): """ 查询任务记录 :param status: :param offset: :param limit: :return: """ q = [] if utils.greater_zero(status, True): q.append('status = $status') where = '' if q: where = 'WHERE %s' % ' AND '.join(q) sdb = db.manager.slave_core with sdb.transaction(): rs = sdb.query(""" SELECT SQL_CALC_FOUND_ROWS * FROM task %(where)s ORDER BY active_time DESC, id DESC LIMIT $offset, $limit; """ % locals(), vars=locals()) if rs: rs2 = sdb.query("""SELECT FOUND_ROWS() AS total_records""") return storage(records=[Task(**r) for r in rs], total_records=rs2[0].total_records) return None
def __init__(self, app, db, session=None, **settings): self._app = app self._db = db if not session: session = web.session.Session(app, web.session.DiskStore('sessions')) self.session = session self.config = utils.storage(utils.dictadd(DEFAULT_SETTINGS, settings)) if 'captcha_func' in self.config.keys(): self.config.captcha_enabled = True hashtype = self.config.get('hash') try: if hashtype == 'sha512': self.hash = hashSha512 elif hashtype == 'sha1': self.hash = hashSha1 elif hashtype == 'bcrypt': self.hash = hashBcrypt else: raise HashError("Hash type must be 'sha512', " "'sha1' or 'bcrypt'") except ImportError: raise HashError('Hash type %s not available' % (hash,)) if self.config.auto_map: self.__mapping()
def __init__(self, **kwargs): super(AuthRole, self).__init__(**kwargs) # 角色列表 self._roles = storage() # 权限列表 self._role_authcodes = []
def init_app(self, app, db, session=None, **settings): self.app = app self.db = db if not session: session = web.session.Session(app, web.session.DiskStore('sessions')) self.session = session self.config = utils.storage(utils.dictadd(DEFAULT_SETTINGS, settings)) if 'captcha_func' in self.config.keys(): self.config.captcha_enabled = True hashtype = self.config.get('hash_type') try: if hashtype == 'sha512': self.hash_func = hash_sha512 elif hashtype == 'sha1': self.hash_func = hash_sha1 elif hashtype == 'bcrypt': self.hash_func = hash_bcrypt else: raise HashError("Hash type must be 'sha512', " "'sha1' or 'bcrypt'") except ImportError: raise HashError('Hash type %s not available' % (hashtype, )) if self.config.auto_map: self.__mapping() return self.app
def callproc(self, sql_query, vars=None, processed=False, _test=False): "调用给定存储过程" if vars is None: vars = {} if not processed and not isinstance(sql_query, web.db.SQLQuery): sql_query = web.db.reparam(sql_query, vars) if _test: return sql_query db_cursor = self._db_cursor() self._db_execute(db_cursor, sql_query) if db_cursor.description: names = [x[0] for x in db_cursor.description] def iterwrapper(): row = db_cursor.fetchone() while row: yield storage(dict(zip(names, row))) row = db_cursor.fetchone() out = web.utils.iterbetter(iterwrapper()) out.__len__ = lambda: int(db_cursor.rowcount) out.list = lambda: [storage(dict(zip(names, x))) \ for x in db_cursor.fetchall()] out = list(out) # 因为是调用存储过程,这里必须关闭游标否则一直报错 db_cursor.close() else: out = db_cursor.rowcount if not self.ctx.transactions: self.ctx.commit() return out
def POST(self): params = {k.replace('file_', ''): v for k, v in web.input().iteritems()} v = video.VideoDAL.add(storage(params)) if v: return 0, 'success', v return messages.NoOperation
def set_last_word(context, w): global last_word, last_context, last_update w = w.lower() #last_word = w s = sha.sha(w) h = s.hexdigest() if h in os.listdir('badwords'): return last_context = context last_update = float(str(time.time())) #datetime.now() words.setdefault(context, []).append(utils.storage(word=w,time=last_update)) """ #folder = 'history/%s/' % context #if not os.path.isdir(folder): # os.mkdir(folder) #fp = open(folder + w, 'a') """ try: if not context: context = "__none__" afile = 'history/%s.txt' % context fp = open(afile, 'a') #codecs.open(.., 'utf-8') fp.write("%s\t%s\n" % (w, last_update)) fp.close() except Exception, e: import traceback traceback.print_exc(e)
def __init__(self, table, keycolnum, *args, **kwargs): self.values = storage() for key, value in kwargs.items(): self.values[key] = value self.table = table self.keycolnum = keycolnum if keycolnum not in self.values.keys(): assert KeyError, "keycolnum 没有对应值"
def env_format(env): "从env信息中提取对统计有用的数据" return storage( # ip 地址 ip=real_ip(env), # 来源地址 referer=env.get('HTTP_REFERER', None), # 当前时间 time=datetime.now().strftime('%Y%m%d'), )
def rs_to_dict(rs, nfield, vfield): """ RecordSet 对象转换为 dict 对象 @rs as RecordSet, 要转换为dict的对象 @nfield as string, 作为key的字段名 @vfield as string, 作为value的字段名 """ raw = storage() map(lambda x: raw.__setattr__(x[nfield], x[vfield]), rs) return raw
def __init__(self, app, session, main_render): self._app = app self.db_session = None self.session = session self.config = utils.storage(utils.dictadd(DEFAULT_SETTINGS)) global render render = main_render hashtype = self.config.get('hash') if hashtype == 'sha512': self.hash = hashSha512 if self.config.auto_map: self.__mapping()
def dict_to_str_insert(data): colnum = "" values = "" for key, value in data.items(): colnum = colnum + key + "," values = values + "${}".format(key) + "," colnum = colnum[:-1] if colnum != "" else "" values = values[:-1] if values != "" else "" if colnum == "": return 101 else: return storage({"colnum": colnum, "values": values})
def __init__(self, url, resource_id, prefix=''): super(ImageSpider, self).__init__() # 抓取地址 self.url = url # 存入七牛的前缀 self.prefix = prefix if not self.prefix.endswith('/'): self.prefix += '/' # 资源id self.resource_id = resource_id # 抓取结果 self.result = storage(success=False, message=u'抓取失败')
def __init__(self, app, store, initializer=None): self.store = store self._initializer = initializer self._last_cleanup_time = 0 self._config = utils.storage(web.config.session_parameters) self._data = utils.threadeddict() if app: app.add_processor(self._processor) self.__getitem__ = self._data.__getitem__ self.__setitem__ = self._data.__setitem__ self.__delitem__ = self._data.__delitem__
class Enum(storage): # 未知项 Unknown = storage(value=-1, text=u'未知', tag='unknown') def find(self, value, default=None): "查找指定值的枚举项" return next(iter(v for v in self.values() if v.value == value), default or self.Unknown) def find_tag(self, tag, default=None): "查找给定tag的枚举项" return next( iter(v for v in self.values() if v.tag.lower() == tag.lower()), default or self.Unknown) def exists(self, item): "给定枚举项是否存在" return any(v for v in self.values() if v == item) def all(self, values): """ 查找所有给定值的枚举项 :param values: list或str, [1,2,3]或'1,2,3'都支持 :return: """ if isinstance(values, (str, unicode)): values = [utils.intval(v) for v in values.split(',')] result = [] for v in values: item = self.find(v) if item != self.Unknown: result.append(item) return result def all_text(self, values, sep=','): """ 查找并获取所有给定值的枚举项的text值 :param values: :param sep: 间隔符, 如果为None则直接范围list :return: """ items = self.all(values) if items: result = [item.text for item in items] return sep.join(result) if sep else result return None
def __init__(self, app, store, initializer=None): self.store = store self._initializer = initializer self._last_cleanup_time = 0 self._config = utils.storage(web.config.session_parameters) self._data = utils.threadeddict() self._origdata = utils.threadeddict() self._session_id_regex = utils.re_compile('^[0-9a-fA-F]+$') self.__getitem__ = self._data.__getitem__ self.__setitem__ = self._data.__setitem__ self.__delitem__ = self._data.__delitem__ if app: app.add_processor(self._processor)
def load(self, url, include_headers=True, method='get', data=None, enable_proxy=False, proxy='default', force=False): "加载给定地址" # 使用的代理 proxies = None # 是否启用代理 if settings.ENABLE_PROXY and enable_proxy: # 使用给定的代理配置 proxies = settings.PROXIES[proxy] while True: request = self.make_request(url, include_headers, force=force) try: func = getattr(request, method) try: resp = func(url, timeout=5, allow_redirects=True, data=data, proxies=proxies) if resp.status_code < 200 or resp.status_code > 299: raise ConnectionError( 'Not 200 (%s) status code found' % resp.status_code) return resp except TooManyRedirects, e: # 重定向次数太多 return storage(status_code=1000, text='') except ConnectionError, ce: # 连接被重置 if self._connection_reset_retry >= 3: raise ce # 连接错误可以重试3次 # 超过3次则抛出异常 log.debug('%s, connection reset retry %s/3', str(ce), self._connection_reset_retry) self._connection_reset_retry += 1 continue
def load_words(): global words, last_context for context in os.listdir('history'): if os.path.isdir('history/' + context): continue fp = open('history/' + context, 'r') data = fp.read() fp.close() for l in data.split("\n"): if not l: continue w, t = l.split("\t") t = float(t) words.setdefault(context, []).append(utils.storage(word=w,time=t)) last_context = context # ... why not ...
def select_with_count(self, where=None, what='*', add_condtion="", vars_value=None, sql_write=None): with self.mdb.transaction(): if sql_write is not None: sql = sql_write else: if where is None: sql = "select SQL_CALC_FOUND_ROWS {} from {} {}".format( what, self.table, add_condtion) else: sql = "select SQL_CALC_FOUND_ROWS {} from {} where {} {}".format( what, self.table, where, add_condtion) rs = self.mdb.query(sql, vars=vars_value) count = self.mdb.query("select FOUND_ROWS() as count")[0].count reslut = storage({"sql_rs": rs, "count": count}) return reslut
def internal(*a, **kw): web.data() # cache it tmpctx = web._context[threading.currentThread()] web._context[threading.currentThread()] = utils.storage(web.ctx.copy()) def newfunc(): web._context[threading.currentThread()] = tmpctx func(*a, **kw) myctx = web._context[threading.currentThread()] for k in myctx.keys(): if k not in ['status', 'headers', 'output']: try: del myctx[k] except KeyError: pass t = threading.Thread(target=newfunc) background.threaddb[id(t)] = t t.start() web.ctx.headers = [] return seeother(changequery(_t=id(t)))
def internal(*a, **kw): web.data() # cache it tmpctx = web._context[threading.currentThread()] web._context[threading.currentThread()] = utils.storage(web.ctx.copy()) def newfunc(): web._context[threading.currentThread()] = tmpctx func(*a, **kw) myctx = web._context[threading.currentThread()] for k in myctx.keys(): if k not in ['status', 'headers', 'output']: try: del myctx[k] except KeyError: pass t = threading.Thread(target=newfunc) background.threaddb[id(t)] = t t.start() web.ctx.headers = [] return web.seeother(web.changequery(_t=id(t)))
def GET(self): menus = [] admin = web.ctx.admin for menu in MENUS: codes = admin.auth.filter([m.code for m in menu.children]) if codes: if menu.children: m = storage(text=menu.text, icon=menu.icon, state=menu.state, type=menu.type, children=[]) for func in menu.children: if func.code in codes: m.children.append({ 'text': func.text, 'state': func.state, 'icon': func.get('icon'), }) menus.append(m) return 0, 'success', menus
def __init__(self, app, db, session=None, **settings): self._app = app self._db = db if not session: session = web.session.Session(app, web.session.DiskStore('sessions')) self.session = session self.config = utils.storage(utils.dictadd(DEFAULT_SETTINGS, settings)) hashtype = self.config.get('hash') try: if hashtype == 'sha512': self.hash = hashSha512 elif hashtype == 'sha1': self.hash = hashSha1 elif hashtype == 'bcrypt': self.hash = hashBcrypt else: raise HashError, "Hash type must be 'sha512', 'sha1' or 'bcrypt'" except ImportError: raise HashError, 'Hash type %s not available' % (hash, ) if self.config.auto_map: self.__mapping()
from web.utils import storage from core import messages from apps import async_response from apps.api import ApiViewBase from apps.api.console import auth_login MENUS = [ # 用户管理 storage(text=u'视频', icon='ti-user', state='console.video', type=1, children=[ storage(text=u'上传视频', state='console.video.upload', code='video_manage'), storage(text=u'视频列表', state='console.video.list', code='video_manage'), ]), # 管理员管理 storage(text=u'管理员', icon='ti-github', state='console.admin', type=4, children=[ storage(text=u'账户设置', state='console.admin.user', code='admin_manage'), storage(text=u'管理角色',
# coding=utf-8 """ 封装短消息发送 """ import urllib from web.utils import storage import http import utils # 消息模板 MESSAGES = storage() # 聚合数据的消息模板id TEMPLATE = storage( # 注册验证码 REGISTER_CODE=7255, # 安全验证码 SAFE_CODE=7256, ) class NotSupported(Exception): pass class SMSBase(http.HttpRequest): "短信接口基类" #def __init__(self, config): # self.config = config
def iterwrapper(): row = db_cursor.fetchone() while row: yield storage(dict(zip(names, row))) row = db_cursor.fetchone()
__all__ = [ 'DBAuth', "AuthError", "HashError", "hash_sha512", "hash_sha1", "hash_bcrypt", "random_password", "temp_password" ] DEFAULT_SETTINGS = utils.storage({ 'auto_map': True, 'captcha_enabled': False, 'url_login': '******', 'url_logout': '/logout', 'url_after_login': '******', # Go there after a successful login 'url_captcha': '/captcha', # Captcha 'template_login': None, 'url_reset_token': '/password_reset', 'url_reset_change': '/password_reset', 'template_reset_token': None, 'template_reset_email': None, 'template_reset_change': None, 'reset_expire_after': 2, # Hours 'hash_type': 'sha512', 'hash_depth': 12, 'db_email_field': 'user_email', 'password_minlen': 6, # Min length of passwords 'forced_delay': 0.5, # Artificial delay to slow down brute-force attacks 'email_from': '', 'captcha_image_type': 'png', # The default captcha image file type }) UNUSABLE_PASSWORD = '******' # This will never be a valid hash class AuthError(Exception):
from os import urandom import sha sha = sha.new import Activity import ldap, ldap.sasl from datetime import datetime from time import sleep render = web.template.render() DEFAULT_SETTINGS = utils.storage({ 'auto_map': True, 'url_login': '******', 'url_logout': '/logout', 'url_after_login': '******', # Go there after a successful login 'hash': 'sha512', 'hash_depth': 12, 'forced_delay': 0.5, # Artificial delay to slow down brute-force attacks }) UNUSABLE_PASSWORD = '******' # This will never be a valid hash web.config.debug = False class HashError(Exception): pass class AuthError(Exception): pass class DBAuth(object): """ Database authentication class.
def _get_d(self): #@@ should really be form.attr, no? return utils.storage([(i.name, i.value) for i in self.inputs])
def get_status(auth_token): status = utils.storage() status.fed = False status.fed_today = False status.lock = True if (auth_token): status.user_name, status.user_id = auth_user(auth_token) else: status.user_name = status.user_id = None # This variable will keep track of whether or not the next feeding time occurs # today, or tomorrow status.next_start_day = 'today' # Cycle name will be "Unscheduled" when called outside of feeding times status.cycle_name = 'unscheduled' # List to be used in next-feed-time calculations nom_times_left = [] db_last_nom = list(config.db.query('SELECT nomnoms.time_stamp,name ' 'FROM nomnoms,users ' 'WHERE nomnoms.user_id = users.id ' 'ORDER BY nomnoms.time_stamp DESC ' 'LIMIT 1')) # If there are no DB entries at least set some date for the last feeding time if db_last_nom.__len__() < 1: status.last_nomtime = datetime(2000, 1, 1, 0, 0) else: status.last_nomtime = db_last_nom[0].time_stamp status.last_feeder = db_last_nom[0].name time_now = datetime.today().time() day_now = datetime.today().date() if status.last_nomtime.date() == day_now: status.fed_today = True # Main loop here - figure out if we're in a feed cycle, if we are then has the # cat already been fed? When does it get fed next? for cycle_name in nom_cycles.iterkeys(): start = nom_cycles[cycle_name]['start'] end = nom_cycles[cycle_name]['end'] if time_now > strphour(start) and time_now < strphour(end): # it's after the cycle start and before the cycle end status.cycle_name = cycle_name if status.last_nomtime.time() > strphour(start) and status.fed_today: # The last feeding was today and the time was after this cycle start # time status.fed = True else: # Cat hasn't been fed today, or was fed at an earlier cycle status.lock = False # Already in the loop, why not build this list of remaining nom_times here? if strphour(start) > time_now: nom_times_left.append(cycle_name) if len(nom_times_left) == 0: # There are no more nom times left today, set the next_start_day to # tomorrow, and set the nom_times_left list to the original nom_cycles list status.next_start_day = 'tomorrow' nom_times_left = list(nom_cycles.iterkeys()) # At this point, if we sort the list of nom_times_left on the start time, the # first position in the list should be the next cycle the feeder will unlock, # and the next_start_day variable should be accurate. nom_times_left.sort(key=lambda cycle_name: nom_cycles[cycle_name]['start'] ) next_cycle = nom_times_left[0] status.next_nom_start = nom_cycles[next_cycle]['start'] status.next_nom_end = nom_cycles[next_cycle]['end'] status.tz = time.tzname[0] return status # Saw this on StackOverflow at # http://stackoverflow.com/questions/4770297/python-convert-utc-datetime-string-to-local-datetime # by user Joe Holloway. Thanks, Joe! def local_to_utc(self, datetime): local_tz = tz.tzlocal() utc_tz = tz.tzutc() datetime = datetime.replace(tzinfo=local_tz) return datetime.astimezone(utc_tz)
from collections import defaultdict import db from cache import cache, cache_delete from core import utils Config = storage( # 数据库相关配置 DB = storage( # 授权表所载数据库名称 Name = 'core', # 数据表 Tables = storage( # 前缀 Prefix = 'auth_', # 功能点表 Function = 'function', # 角色表 Role = 'role', # 角色与功能点关联表 RoleFunctionMap = 'role_function', # 用户与角色关联表 RoleMap = 'role_map', ), ), ) class AuthRole(storage): "角色实体" def __init__(self, **kwargs): super(AuthRole, self).__init__(**kwargs)
# coding=utf-8 from web.utils import storage from core.libs.enum import Enum # 视频相关 Video = storage( # 状态 Status = Enum( Pending = storage(value = 'pending', text = '挂起中', label = 'default'), Segmenting = storage(value = 'segmenting', text = '分片中', label = 'warning'), Storing = storage(value = 'storing', text = '转存中', label = 'warning'), Completed = storage(value = 'completed', text = '完成', label = 'success'), Deleting = storage(value = 'deleting', text = '删除中', label = 'danger'), Error = storage(value = 'error', text = '错误', label = 'danger'), Unknown = storage(value = 'Unknown', text = '未知', label = 'default') ), ) # 权限相关 Auth = storage( # 功能类型 FunctionType = Enum( # 视频相关功能 Video = storage(value = 1, text = u'视频', tag = 'Video'), # 管理用户相关功能 Administrator = storage(value = 4, text = u'管理用户', tag = 'Administrator'), # 任务管理相关功能 Task = storage(value = 99, text = u'任务管理', tag = 'Task'), ),
def context(self): return storage(user=users.get_current_user(), loginurl=self.loginurl(), logouturl=users.create_logout_url("/"))
def query(self, search): """Query the local Google Desktop Search http server.""" # import web # web.debug("querying " + self.query_url(search)) data = urlgrabber.urlread(self.query_url(search)) pg = BeautifulSoup(data) # get first 10 results, can get more via links to other pages results = [] if not windows: results = pg.findAll("div", {"class": "searchresult"}) if len(results) == 1 and data.find("did not match any items") > -1: results = [] else: results = pg.findAll("table", {"cellspacing": "0", "cellpadding": "0", "border": "0"}) # remove non results... results = results[4:] results = results[:-4] # TODO: sort by relevance instead of date import web i = 1 stored_results = [] for r in results: # this is all windows specific below.. sr = utils.storage() stored_results.append(sr) sr.img = "" img = r.findAll("img") if img: img = img[0]["src"] sr.img = self.__class__.baseaddr + "/" + img.strip("/") # web.debug('img: ' + sr.img) # sr.img = 'http://127.0.0.1:4664/zip.gif' # print "image src:", sr.img links = r.findAll("a") # use these sr.links = links itemloc = "" if windows: sel = r.find("span") itemloc = subcontent(sel, html=False) if sel.find("a"): itemloc = "" sr.itemloc = itemloc else: sel = r.find("span", {"class": "url"}) if not sel: pass # import web # web.debug(r) else: itemloc = sel["title"] sr.itemloc = itemloc itemlink = links[0] itemlink["title"] = itemloc sr.itemlink = itemlink otherlinks = r.findAll("a", {"class": "c"}) sr.otherlinks = otherlinks snippet = "" if windows: sel = r.find("font") snippet = subcontent(sel, html=False) # oy.. if sel.find("a"): # why do i do this? snippet = "" else: sel = r.find("span", {"class": "snippet"}) if sel: snippet = subcontent(sel, html=False) sr.snippet = snippet.strip().strip("<br />") """ print snippet, '<br />' print img, '<br />' print itemlink, '<br />' print itemloc, '<br />' print otherlinks[0], '<br />' """ # TODO: links to web pages, need to open in a separate browser... # convert most links to ajax get requests on Google Desktop to perform operations for l in links: l["href"] = self.__class__.baseaddr + l["href"] # if l.string and l.string.find('cache') > -1 and (l['href'].find('versions') > -1 or l['href'].find('cache') > -1): # pass # else: # print l.string, l['href'] l[ "onclick" ] = "$.get('open?href=' + encodeURIComponent($(this).attr('href')) + '&d=' + new Date().toUTCString());return false;" # change to ajax call on the link so Google desktop opens.. # snippet in span .snippet return stored_results
import os import random import urllib2 import requests from requests.exceptions import TooManyRedirects, ConnectionError from web.utils import storage import log import settings # 全局会话 SESSION = storage( # 请求次数 length=0, # 实际的会话实例 session=None, ) USER_AGENTS = ( 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;', 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)', 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1', 'Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1', 'Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11', 'Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11', 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)', 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)',
from .views import AuthError DEFAULT_SETTINGS = utils.storage({ 'auto_map': True, 'captcha_enabled': False, 'url_login': '******', 'url_logout': '/logout', 'url_after_login': '******', # Go there after a successful login 'url_captcha': '/captcha', # Captcha 'template_login': None, 'url_reset_token': '/password_reset', 'url_reset_change': '/password_reset', 'template_reset_token': None, 'template_reset_email': None, 'template_reset_change': None, 'reset_expire_after': 2, # Hours 'hash': 'sha512', 'hash_depth': 12, 'db_email_field': 'user_email', 'password_minlen': 6, # Min length of passwords 'forced_delay': 0.5, # Artificial delay to slow down brute-force attacks 'email_from': '', 'captcha_image_type': 'png', # The default captcha image file type }) UNUSABLE_PASSWORD = '******' # This will never be a valid hash
import traceback import sys DEFAULT_SETTINGS = utils.storage( { "auto_map": True, "captcha_enabled": False, "url_login": "******", "permission_deny": "/permdeny", "url_logout": "/logout", "url_signup": "/signup", "url_after_login": "******", # Go there after a successful login "url_captcha": "/captcha", # Captcha "template_login": None, "url_reset_token": "/password_reset", "url_reset_change": "/password_reset", "template_reset_token": None, "template_reset_email": None, "template_reset_change": None, "reset_expire_after": 2, # Hours "hash": "sha512", "hash_depth": 12, "db_email_field": "user_email", "password_minlen": 6, # Min length of passwords "forced_delay": 0.5, # Artificial delay to slow down brute-force attacks "email_from": "", "captcha_image_type": "png", # The default captcha image file type } ) UNUSABLE_PASSWORD = "******" # This will never be a valid hash
data = fp.read() fp.close() data = re.sub('(, |{)\'?([a-z_A-Z0-9\.]+)\'?:', "\\1\"\\2\":", data[1:-1]) d = cjson.decode(data) # to same form as tabmix below windows = [] for w in d['windows']: tabs = [] for t in w['tabs']: tab = [] entries = t['entries'] entries.reverse() for e in entries: # i don't know what multiple entries mean.. tab.append(storage(url=e['url'], title=e['title'])) if e.has_key('children'): children = e['children'] #children.reverse() for c in children: tab.append(storage(url=c['url'], title='(unknown)')) tabs.append(tab) windows.append(tabs) # hmm, children info is misleading.. # and some of the tabs it gives aren't open any more and they aren't the last ones opened.. # TabMix Plus # not sure how to get windows.. may involve the sequences or some of the other attributes..
import sys import os os.chdir('/var/www/mowmow/') sys.path.append('/var/www/mowmow/api') sys.path.append('/var/www/mowmow/api/mowlib/') import mow_utils import config from web import utils db = config.db print(status) if status['fed']: print('Already fed') else: print('Feeding') data = utils.storage(feed=1) mow_utils.feed_cycle(data, mow_utils.date_strings(), None, external=True)
import sys import os os.chdir('/var/www/mowmow/') sys.path.append('/var/www/mowmow/api') sys.path.append('/var/www/mowmow/api/mowlib/') import mow_utils import config from web import utils db = config.db print(status) if status['fed']: print('Already fed') else: print('Feeding') data = utils.storage(feed = 1) mow_utils.feed_cycle(data, mow_utils.date_strings(), None, external=True)
# coding=utf-8 from web.utils import storage from core import utils from core.libs import cache, db # 比较器 Comparer = storage( # 开区间比较 OpenInterval=lambda x, value: utils.floatval(x[ 0]) < value and utils.floatval(x[1]) > value, # 闭区间比较 ClosedInterval=lambda x, value: utils.floatval(x[ 0]) <= value and utils.floatval(x[1]) >= value, # 左开右闭 LeftOpenInterval=lambda x, value: utils.floatval(x[ 0]) < value and utils.floatval(x[1]) >= value, # 左闭右开 LeftClosedInterval=lambda x, value: utils.floatval(x[0]) <= value and utils .floatval(x[1]) > value, ) class DBConfig(storage): def __init__(self, table_name, items): self.raw_items = items self.table_name = table_name if items: super(DBConfig, self).__init__(**{item.name: item.value
web.config.debug = True # ====== 数据库相关配置 ====== DATABASES = storage( # 核心库 core=storage( master=storage( db='amengsms', user='******', pw='163888', host='127.0.0.1', port=3306, ), slaves=[], ), # 媒体库 media=storage( master=storage( db='amengsms_media', user='******', pw='163888', host='127.0.0.1', port=3306, ), slaves=[], ), ) # ====== 缓存配置 ====== CACHED = storage( # 使用的缓存驱动
"""global variables always kept in memory module is named glbl since global is reserved.""" __all__ = ["constant","variable","perm","role","url_dst","url_src"] import loader inc = loader.import_('includes') from web.utils import storage constant = storage({ 'anonymous_role_id':1, 'authenticated_role_id':2, 'remember_me_length':2592000, #30 days 'watchdog_notice':0, 'watchdog_warning':1, 'watchdog_error':2, }) # ## Database tables kept in memory # variable = inc.util.Variable('variable', key_field='name', value_field='value') # Keeping permissions and roles in memory probably isn't a great idea if # there's going to be lots and lots of roles. um, but ok since I only have a few. perm = inc.util.Variable('permission', key_field='rid', value_field='perm') role = inc.util.Variable('role', key_field='rid', value_field='name') # src is the place the actual page is. # e.g. 'node/186' is the src, 'about' is the dst