<commit_before>#!/usr/bin/env python
#coding:utf-8
from twisted.python import log
from bottle import request
from bottle import response
from bottle import redirect
from bottle import HTTPError
from bottle import static_file
from bottle import mako_template
from toughradius.console.libs.paginator import Paginator
from toughradius.console.libs import utils
from toughradius.console import models
from beaker.cache import CacheManager
from hashlib import md5
import logging
import functools
import urllib
import json
import time
import tempfile

########################################################################
# const define
########################################################################

FEES = (PPMonth,PPTimes,BOMonth,BOTimes,PPFlow,BOFlows) = (0,1,2,3,4,5)

ACCOUNT_STATUS = (UsrPreAuth,UsrNormal,UsrPause,UsrCancel,UsrExpire) = (0,1,2,3,4)

CARD_STATUS = (CardInActive,CardActive,CardUsed,CardRecover) = (0,1,2,3)

CARD_TYPE = (ProductCard,BalanceCard) = (0,1)

ACCEPT_TYPES = {
    'open':u'开户',
    'pause':u'停机',
    'resume':u'复机',
    'cancel':u'销户',
    'next':u'续费',
    'charge':u'充值',
    'change':u'变更'
}

MAX_EXPIRE_DATE = '3000-12-30'

TMPDIR = tempfile.gettempdir()

page_size = 20

__cache_timeout__ = 600

cache = CacheManager(cache_regions={'short_term':{ 'type': 'memory', 'expire': __cache_timeout__ }}) 
   
class Connect:
    def __init__(self, mkdb):
        self.conn = mkdb()

    def __enter__(self):
        return self.conn   

    def __exit__(self, exc_type, exc_value, exc_tb):
        self.conn.close()

class SecureCookie(object):
    
    def setup(self,secret):
        self.secret = secret
    
    def get_cookie(self,name):
        return request.get_cookie(md5(name).hexdigest(),secret=self.secret)
        
    def set_cookie(self,name,value,**options):
        response.set_cookie(md5(name).hexdigest(),value,secret=self.secret,**options)
        
scookie = SecureCookie()
get_cookie = scookie.get_cookie
set_cookie = scookie.set_cookie

class Render(object):
    
    RENDERS = {}
    
    def __init__(self,context={},lookup=None):
        self.context = context
        self.lookup = lookup

    def render(self,*args,**kwargs):
        kwargs['template_lookup'] = self.lookup
        kwargs.update(**self.context)
        return mako_template(*args,**kwargs)
    
    @staticmethod 
    def render_app(app,*args,**kwargs):
        render_obj = Render.RENDERS[app.config['render_key']]
        return render_obj.render(*args,**kwargs)
        
########################################################################
# permission manage
########################################################################

class Permit():
    routes = {}
    def add_route(self,path,name,category,is_menu=False,order=time.time(),is_open=True):
        if not path:return
        self.routes[path] = dict(
            path=path,
            name=name,
            category=category,
            is_menu=is_menu,<commit_msg>query unicode param bug fix<commit_after>#!/usr/bin/env python
#coding:utf-8
from twisted.python import log
from bottle import request
from bottle import response
from bottle import redirect
from bottle import HTTPError
from bottle import static_file
from bottle import mako_template
from toughradius.console.libs.paginator import Paginator
from toughradius.console.libs import utils
from toughradius.console import models
from beaker.cache import CacheManager
from hashlib import md5
import logging
import functools
import urllib
import json
import time
import tempfile

########################################################################
# const define
########################################################################

FEES = (PPMonth,PPTimes,BOMonth,BOTimes,PPFlow,BOFlows) = (0,1,2,3,4,5)

ACCOUNT_STATUS = (UsrPreAuth,UsrNormal,UsrPause,UsrCancel,UsrExpire) = (0,1,2,3,4)

CARD_STATUS = (CardInActive,CardActive,CardUsed,CardRecover) = (0,1,2,3)

CARD_TYPE = (ProductCard,BalanceCard) = (0,1)

ACCEPT_TYPES = {
    'open':u'开户',
    'pause':u'停机',
    'resume':u'复机',
    'cancel':u'销户',
    'next':u'续费',
    'charge':u'充值',
    'change':u'变更'
}

MAX_EXPIRE_DATE = '3000-12-30'

TMPDIR = tempfile.gettempdir()

page_size = 20

__cache_timeout__ = 600

cache = CacheManager(cache_regions={'short_term':{ 'type': 'memory', 'expire': __cache_timeout__ }}) 
   
class Connect:
    def __init__(self, mkdb):
        self.conn = mkdb()

    def __enter__(self):
        return self.conn   

    def __exit__(self, exc_type, exc_value, exc_tb):
        self.conn.close()

class SecureCookie(object):
    
    def setup(self,secret):
        self.secret = secret
    
    def get_cookie(self,name):
        return request.get_cookie(md5(name).hexdigest(),secret=self.secret)
        
    def set_cookie(self,name,value,**options):
        response.set_cookie(md5(name).hexdigest(),value,secret=self.secret,**options)
        
scookie = SecureCookie()
get_cookie = scookie.get_cookie
set_cookie = scookie.set_cookie

class Render(object):
    
    RENDERS = {}
    
    def __init__(self,context={},lookup=None):
        self.context = context
        self.lookup = lookup

    def render(self,*args,**kwargs):
        kwargs['template_lookup'] = self.lookup
        kwargs['template_settings'] = dict(
            input_encoding='utf-8',
            output_encoding='utf-8', 
            encoding_errors='replace'
        )
        kwargs.update(**self.context)
        return mako_template(*args,**kwargs)
    
    @staticmethod 
    def render_app(app,*args,**kwargs):
        render_obj = Render.RENDERS[app.config['render_key']]
        return render_obj.render(*args,**kwargs)
        
########################################################################
# permission manage
########################################################################

class Permit():
    routes = {}
    def add_route(self,path,name,category,is_menu=False,order=time.time(),is_open=True):
        if not path:return
        self.routes[path] = dict(
            path=path,
            name=name,
            category=category,
            is_menu=is_menu,
{'fraction_non_alphanumeric': 0.20417482061317677, 'fraction_numerical': 0.01141552511415525, 'mean_word_length': 4.047736625514403, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6019688', 'n_tokens_mistral': 1933, 'n_tokens_neox': 1888, 'n_words': 356}