# Path: mod/_config.py

# 
# Path: mod/models/srtp_cache.py
# class SRTPCache(Base):
#     __tablename__ = 'srtp_cache'
#     cardnum = Column(String(16), primary_key=True)
#     text = Column(String(4096), nullable=False)
#     date = Column(Integer, nullable=False)


from .._config import srtpCacheTime
from sqlalchemy.orm.exc import NoResultFound
from config import SRTP_URL, TIME_OUT
from tornado.httpclient import HTTPRequest, AsyncHTTPClient
from BeautifulSoup import BeautifulSoup
from time import time
from ..models.srtp_cache import SRTPCache
import base64
import tornado.web
import tornado.gen
import urllib
import json
import re
# -*- coding: utf-8 -*-
# @Date    : 2014-06-27 14:36:45
# @Author  : xindervella@gamil.com yml_bright@163.com



class SRTPHandler(tornado.web.RequestHandler):

    @property
    def db(self):
        return self.application.db
    def on_finish(self):
        self.db.close()
    def get(self):
        self.write('Herald Web Service')


    @tornado.web.asynchronous
    @tornado.gen.engine
    def post(self):
        number = self.get_argument('number', default=None)
        retjson = {'code':200, 'content':''}
        status = None

        if not number:
            retjson['code'] = 400
            retjson['content'] = 'params lack'
        else:
            #read from cache
            try:

# Path: mod/_config.py

# 
# Path: mod/models/srtp_cache.py
# class SRTPCache(Base):
#     __tablename__ = 'srtp_cache'
#     cardnum = Column(String(16), primary_key=True)
#     text = Column(String(4096), nullable=False)
#     date = Column(Integer, nullable=False)


# Path: mod/srtp/srtp_handler.py
from .._config import srtpCacheTime
from sqlalchemy.orm.exc import NoResultFound
from config import SRTP_URL, TIME_OUT
from tornado.httpclient import HTTPRequest, AsyncHTTPClient
from BeautifulSoup import BeautifulSoup
from time import time
from ..models.srtp_cache import SRTPCache
import base64
import tornado.web
import tornado.gen
import urllib
import json
import re

# -*- coding: utf-8 -*-
# @Date    : 2014-06-27 14:36:45
# @Author  : xindervella@gamil.com yml_bright@163.com



class SRTPHandler(tornado.web.RequestHandler):

    @property
    def db(self):
        return self.application.db
    def on_finish(self):
        self.db.close()
    def get(self):
        self.write('Herald Web Service')


    @tornado.web.asynchronous
    @tornado.gen.engine
    def post(self):
        number = self.get_argument('number', default=None)
        retjson = {'code':200, 'content':''}
        status = None

        if not number:
            retjson['code'] = 400
            retjson['content'] = 'params lack'
        else:
            #read from cache
            try:

                status = self.db.query(SRTPCache).filter(SRTPCache.cardnum == number).one()