Beispiel #1
0
 def __init__(self,request=None, response=None):
     self.initialize(request, response)
     self.errorMsg = ''
     try:
         self.dictionary = Dictionary.create_default()
     except Exception as e:
         print Exceptions.format_exception(e)
Beispiel #2
0
 def get(self):
     user = users.get_current_user()
     if user:
         if self.request.get('keys'):
             try:
                 filtered = self.dictionary.filter(self.request.get('keys'), self.request.get('require'))
                         
                 self.dictionary.augment_with_rank(filtered)
                 
                 material = self.dictionary.prepare_for_quiz(filtered)
                 
             except Exception, e:
                 print Exceptions.format_exception(e)
             
             if self.errorMsg is not '':
                 self.set_cookie('error', str(self.errorMsg))
         
             self.response.out.write(json.dumps(material))    
         elif self.request.get('unit'):
             material = self.get_material(int(self.request.get('unit')), self.request.get('stage') == 'review')
             self.response.out.write(material)
         elif self.request.get('recent'):
             disciple = Disciple.get_current(user)
             material = self.dictionary.prepare_for_quiz(json.loads(disciple.recent_mastered))
             self.response.out.write(json.dumps(material))
Beispiel #3
0
 def get(self):
     user = users.get_current_user()
     if user:
         if self.request.get('keys'):
             try:
                 filtered = self.dictionary.filter(self.request.get('keys'), self.request.get('require'))
                         
                 self.dictionary.augment_with_rank(filtered)
                 
                 material = self.dictionary.prepare_for_quiz(filtered)
                 
             except Exception, e:
                 print Exceptions.format_exception(e)
             
             if self.errorMsg is not '':
                 self.set_cookie('error', str(self.errorMsg))
         
             self.response.out.write(json.dumps(material))    
         elif self.request.get('unit'):
             material = self.get_material(int(self.request.get('unit')) - 1, self.request.get('stage') == 'review')
             self.response.out.write(material)
         elif self.request.get('recent'):
             disciple = Disciple.get_current(user)
             material = self.dictionary.prepare_for_quiz(json.loads(disciple.recent_mastered))
             self.response.out.write(json.dumps(material))
Beispiel #4
0
 def __init__(self,request=None, response=None):
     self.initialize(request, response)
     self.errorMsg = ''
     try:
         self.dictionary = Dictionary.create_default()
     except Exception as e:
         print Exceptions.format_exception(e)
Beispiel #5
0
 def _f(object_to_check):
     log.info('{}, args: {}'.format(f_object, object_to_check))
     for segment in object_to_check.split('.'):
         if int(segment) > 255:
             raise Exceptions.FailCheckDigitIP('Oops :)')
     log.info('Function: {}, Status: OK'.format(f_object.__name__))
     return f_object(object_to_check)
Beispiel #6
0
 def _f(object_to_check):
     log.info('{}, args: {}'.format(f_object, object_to_check))
     if not ''.join(object_to_check.split('.')).isdigit():
         raise Exceptions.FailCheckDigitIP(
             '{} should contain numbers and dots'.format(object_to_check))
     log.info('Function: {}, Status: OK'.format(f_object.__name__))
     return f_object(object_to_check)
Beispiel #7
0
 def __init__(self, request=None, response=None):
     self.initialize(request, response)
     self.error_msg = ''
     try:
         self.dictionary = Dictionary.create_default()
     except Exception, e:
         self.error_msg += Exceptions.print_exception(e)
Beispiel #8
0
 def __init__(self, request=None, response=None):
     self.initialize(request, response)
     self.error_msg = ''
     try:
         self.dictionary = Dictionary.create_default()
     except Exception, e:
         self.error_msg += Exceptions.print_exception(e)
Beispiel #9
0
 def _f(object_to_check):
     log.info('{}, args: {}'.format(f_object, object_to_check))
     for segment in object_to_check.split('.'):
         if len(segment) > 3:
             raise Exceptions.FailCheckDigitIP(
                 'Every segment must consist of from one to three digits')
     log.info('Function: {}, Status: OK'.format(f_object.__name__))
     return f_object(object_to_check)
Beispiel #10
0
 def _f(*object_to_check):
     log.info('{}, args: {}'.format(f_object, *object_to_check))
     # This part of function need for check input parameter that to ensure the safe execution of the function
     for index, argument in enumerate(inspect.getfullargspec(f_object)[0]):
         if not isinstance(object_to_check[index],
                           f_object.__annotations__[argument]):
             raise Exceptions.FailCheckStr(
                 'object_to_check <{}> must be <str> type'.format(
                     *object_to_check))
     log.info('Function: {}, Status: OK'.format(f_object.__name__))
     return f_object(*object_to_check)
Beispiel #11
0
 def _f(object_to_check):
     log.info('{}, args: {}'.format(f_object, object_to_check))
     try:
         sample = object_to_check.split('.')
     except Exception as err:
         log.error(err)
         raise err
     if len(sample) != 4:
         raise Exceptions.FailCheckLenIP(
             'len({}) must be 4'.format(object_to_check))
     log.info('Function: {}, Status: OK'.format(f_object.__name__))
     return f_object(object_to_check)
Beispiel #12
0
    def __init__(self, ip=None, _port=None, data_cb=None, sys_cb=None,
                 word_for_check_new_acceptance={'request': None, 'response': None}, _run_timer=False):
        """

        :param ip:
        :param port:
        :param callback:
        :param word_for_check_new_acceptance: must be list type with 2 include, for example, ['request', 'response']
        :return:
        """
        if not self._check_args(ip, _port, data_cb, sys_cb, word_for_check_new_acceptance, _run_timer):
            log.error(Exceptions.FailCheckServerArgs('Oops :) Some args are incorrect'))
            raise Exceptions.FailCheckServerArgs('Oops :) Some args are incorrect')

        self.sock = None
        self.ip = ip
        self.port = _port
        self.data_callback = data_cb
        self.sys_callback = sys_cb
        self.is_check_new_acceptance = word_for_check_new_acceptance

        threading.Thread.__init__(self)

        self.flag_run = False
        self.info = dict()
        self.queue_handlers = {'acceptance': self.accept_handler,
                               'accept error': self.accept_error_handler,
                               'speak': self.speak_handler,
                               'speak error': self.speak_error_handler,
                               'control': self.cmd_handler
                               }

        self.acceptThread = Thread4Accept()
        self.speakThread = dict()

        if _run_timer:
            self.timer = Interrupt(callback_handler=self.callback_for_timer, periodic=1)
Beispiel #13
0
 def get(self):
     """Performs lookup on dictionary, augmenting with user's data"""
     user = users.get_current_user()
     if user:
         data = None
         export = []
         try:
             if self.request.get('keys'):
                 data = self.dictionary.filter(self.request.get('keys'), self.request.get('require'))
             else:
                 data = self.dictionary.filter("")
         except Exception, e:
             self.error_msg += Exceptions.format_exception(e)
                                 
         for k in data:
             export.append({'word': data[k], 'stroke': k})
             
         if self.error_msg is not '':
             self.set_cookie('error', str(self.error_msg))
             self.response.out.write(str(self.error_msg))
         else:
             self.response.out.write(json.dumps(export))
Beispiel #14
0
    def get(self):
        """Performs lookup on dictionary, augmenting with user's data"""
        user = users.get_current_user()
        if user:
            data = None
            export = []
            try:
                if self.request.get('keys'):
                    data = self.dictionary.filter(self.request.get('keys'),
                                                  self.request.get('require'))
                else:
                    data = self.dictionary.filter("")
            except Exception, e:
                self.error_msg += Exceptions.format_exception(e)

            for k in data:
                export.append({'word': data[k], 'stroke': k})

            if self.error_msg is not '':
                self.set_cookie('error', str(self.error_msg))
                self.response.out.write(str(self.error_msg))
            else:
                self.response.out.write(json.dumps(export))
Beispiel #15
0
 def _f(object_to_check):
     log.info('{}, args: {}'.format(f_object, object_to_check))
     if object_to_check > 65536:
         raise Exceptions.FailCheckMaxValue('Oops :)')
     log.info('Function: {}, Status: OK'.format(f_object.__name__))
     return f_object(object_to_check)