# Path: odpw/utils/timing.py
# class Timer(object):
# 
#     measures={}
# 
#     def __init__(self, verbose=False, key=None):
#         self.verbose = verbose
#         self.key=key
# 
#     def __enter__(self):
#         self.start = time.time()
#         return self
# 
#     def __exit__(self, *args):
#         end = time.time()
#         secs = end - self.start
#         msecs = secs * 1000  # millisecs
#         if self.verbose:
#             print '(%s) elapsed time: %f ms' % (self.key,msecs)
#         if self.key:
#             if self.key not in self.__class__.measures:
#                 self.__class__.measures[self.key]=faststat.Stats()
#             if msecs>=0:
#                 self.__class__.measures[self.key].add(msecs)
# 
# 
#     @classmethod
#     def printStats(cls):
#         print '>>>','--*'*10,'TIMER','*--'*10
#         s=[" Timing stats:","\n"]
#         for m,st in Timer.measures.items():
#             p = st.percentiles
#             if st.n < len(p):
#                 quartiles = "(n too small)"
#             else:
#                 quartiles = (_sigfigs(p.get(0.25, -1)),
#                     _sigfigs(p.get(0.5, -1)), _sigfigs(p.get(0.75, -1)))
#             d = ["  ["+m+'] -', str(st.mean), 'avg ms for',m,str(st.n),'calls)'
#                     ,"\n       (min:",str(st.min),"-",str(st.max),":max, quantils:",quartiles,")\n"]
#             s=s+d
#         s=s+['-'*50]
#         print " ".join(s)
#         print '<<<','--*'*10,'TIMER','*--'*10
# 
#     @classmethod
#     def getStats(cls):
# 
#         stats={}
#         for m,st in cls.measures.items():
#             p = st.percentiles
#             stats[m]={
#                 'avg':st.mean
#                 , 'calls':st.n
#                 , 'min':st.min
#                 , 'max':st.max
#                 , 'q25':None, 'q5':None, 'q75':None
#             }
#             if st.n < len(p):
#                 quartiles = "(n too small)"
#             else:
#                 stats[m]['q25']=_sigfigs(p.get(0.25, -1))
#                 stats[m]['q5']=_sigfigs(p.get(0.5, -1))
#                 stats[m]['q75']=_sigfigs(p.get(0.75, -1))
#         return stats
# 
# Path: odpw/utils/error_handling.py
# class ErrorHandler():
# 
#     exceptions=defaultdict(long)
# 
#     DEBUG=False
# 
#     @classmethod
#     def handleError(cls, log, msg=None, exception=None, debug=False, **kwargs):
#         name=type(exception).__name__
#         cls.exceptions[name] +=1
# 
#         if debug:
#             print(traceback.format_exc())
# 
#         log.error(msg, exctype=type(exception), excmsg=exception.message, **kwargs)
# 
#     @classmethod
#     def printStats(cls):
#         print '>>>','--*'*10,'EXCEPTIONS','*--'*10
#         if len(cls.exceptions)==0:
#             print "No exceptions handled"
#         else:
#             print "  Numbers of Exceptions:"
#             for exc, count in cls.exceptions.iteritems():
#                 print " ",exc, count
#         print '<<<','--*'*25


import argparse
import logging.config
import os
import structlog
import time
import sys
import odpw
import yaml
        import traceback
from odpw.utils.timing import Timer
from odpw.utils.error_handling import ErrorHandler
from odpw_restapi import api, conv, qa
from tornado.web import RequestHandler
from tornado.wsgi import WSGIContainer
from flask import Flask, jsonify, request, Blueprint




log =structlog.get_logger()




def config_logging():

    structlog.configure(

# Path: odpw/utils/timing.py
# class Timer(object):
# 
#     measures={}
# 
#     def __init__(self, verbose=False, key=None):
#         self.verbose = verbose
#         self.key=key
# 
#     def __enter__(self):
#         self.start = time.time()
#         return self
# 
#     def __exit__(self, *args):
#         end = time.time()
#         secs = end - self.start
#         msecs = secs * 1000  # millisecs
#         if self.verbose:
#             print '(%s) elapsed time: %f ms' % (self.key,msecs)
#         if self.key:
#             if self.key not in self.__class__.measures:
#                 self.__class__.measures[self.key]=faststat.Stats()
#             if msecs>=0:
#                 self.__class__.measures[self.key].add(msecs)
# 
# 
#     @classmethod
#     def printStats(cls):
#         print '>>>','--*'*10,'TIMER','*--'*10
#         s=[" Timing stats:","\n"]
#         for m,st in Timer.measures.items():
#             p = st.percentiles
#             if st.n < len(p):
#                 quartiles = "(n too small)"
#             else:
#                 quartiles = (_sigfigs(p.get(0.25, -1)),
#                     _sigfigs(p.get(0.5, -1)), _sigfigs(p.get(0.75, -1)))
#             d = ["  ["+m+'] -', str(st.mean), 'avg ms for',m,str(st.n),'calls)'
#                     ,"\n       (min:",str(st.min),"-",str(st.max),":max, quantils:",quartiles,")\n"]
#             s=s+d
#         s=s+['-'*50]
#         print " ".join(s)
#         print '<<<','--*'*10,'TIMER','*--'*10
# 
#     @classmethod
#     def getStats(cls):
# 
#         stats={}
#         for m,st in cls.measures.items():
#             p = st.percentiles
#             stats[m]={
#                 'avg':st.mean
#                 , 'calls':st.n
#                 , 'min':st.min
#                 , 'max':st.max
#                 , 'q25':None, 'q5':None, 'q75':None
#             }
#             if st.n < len(p):
#                 quartiles = "(n too small)"
#             else:
#                 stats[m]['q25']=_sigfigs(p.get(0.25, -1))
#                 stats[m]['q5']=_sigfigs(p.get(0.5, -1))
#                 stats[m]['q75']=_sigfigs(p.get(0.75, -1))
#         return stats
# 
# Path: odpw/utils/error_handling.py
# class ErrorHandler():
# 
#     exceptions=defaultdict(long)
# 
#     DEBUG=False
# 
#     @classmethod
#     def handleError(cls, log, msg=None, exception=None, debug=False, **kwargs):
#         name=type(exception).__name__
#         cls.exceptions[name] +=1
# 
#         if debug:
#             print(traceback.format_exc())
# 
#         log.error(msg, exctype=type(exception), excmsg=exception.message, **kwargs)
# 
#     @classmethod
#     def printStats(cls):
#         print '>>>','--*'*10,'EXCEPTIONS','*--'*10
#         if len(cls.exceptions)==0:
#             print "No exceptions handled"
#         else:
#             print "  Numbers of Exceptions:"
#             for exc, count in cls.exceptions.iteritems():
#                 print " ",exc, count
#         print '<<<','--*'*25


# Path: api/server.py
import argparse
import logging.config
import os
import structlog
import time
import sys
import odpw
import yaml
        import traceback
from odpw.utils.timing import Timer
from odpw.utils.error_handling import ErrorHandler
from odpw_restapi import api, conv, qa
from tornado.web import RequestHandler
from tornado.wsgi import WSGIContainer
from flask import Flask, jsonify, request, Blueprint





log =structlog.get_logger()




def config_logging():

    structlog.configure(

        processors=[