def term(user_id):
    """
    Continuously stream new terminal messages.
    :param user_id: float -- the id of the user whose terminal we want
    """

    def pr_term(_user_id):
        print('Getting terminal text for user %s' % _user_id)
        while True:
            target = TERM_TEXT.get_text(user_id)
            yield target
            time.sleep(.100)

    return app.response_class(pr_term(user_id), mimetype='text/html')
def get_pos(user_id):
    def pos(_user_id):
        """
        Continuously stream current millisecond position of video.
        :param _user_id: float -- the id of the user whose video we want
        """

        # Wait until a video is ready
        while not CUR_VIDEO.get(_user_id):
            time.sleep(.300)
        # Continuously stream video position, delimited by exclamation points
        while True:
            # Id of CAP_PROP_POS_MSEC is 0
            yield "!!!" + str(CUR_VIDEO[_user_id].video.get(0))
            time.sleep(.500)

    return app.response_class(pos(user_id), mimetype='text/plain')
Exemple #3
0
 def _view(_argument, action=None):
     return app.response_class(_argument,
                               mimetype='application/json',
                               status=200)
Exemple #4
0
    def _parse_parameters(self, extra_params=()):
        parser = reqparse.RequestParser()
        for name, param_type in extra_params:
            parser.add_argument(name, type=param_type)
        return parser.parse_args()

    def _render(self, content, code=200):
        try:
            content = json.dumps(content, default=encode_model)
        except Exception, exc:
            msg = 'Error when dump data: %s' % exc
            logging.error(msg)
            return odesk_error_response(500, ERR_INVALID_DATA, msg, exc)

        return app.response_class(content, mimetype='application/json'), code


class BaseResourceSQL(BaseResource):
    """ Base REST resource for SQL models. """

    # ==== GET ====

    # List related methods
    def _get_list_query(self, params, **kwargs):
        def get_order():
            order = params.get('order', 'asc')
            try:
                return self.ORDER_DICT[order]
            except KeyError as e:
                raise ValidationError('Invalid order. It could be asc or desc',
def jsonify_response(response, status=200):
    """ Returns the dict response as json with the provided status code """
    return app.response_class(response=json.dumps(response),
                              status=status,
                              mimetype="application/json")