Python flask_restful.fields.Integer() Examples

The following are 12 code examples of flask_restful.fields.Integer(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module flask_restful.fields , or try the search function .
Example #1
Source File: gateway.py    From floranet with MIT License 6 votes vote down vote up
def __init__(self, **kwargs):
        self.restapi = kwargs['restapi']
        self.server = kwargs['server']
        self.fields = {
            'host': fields.String,
            'eui': fields.Integer,
            'name': fields.String,
            'enabled': fields.Boolean,
            'power': fields.Integer,
            'created': fields.DateTime(dt_format='iso8601'),
            'updated': fields.DateTime(dt_format='iso8601')
        }
        self.parser = reqparse.RequestParser(bundle_errors=True)
        self.parser.add_argument('host', type=str)
        self.parser.add_argument('eui', type=int)
        self.parser.add_argument('name', type=str)
        self.parser.add_argument('enabled', type=inputs.boolean)
        self.parser.add_argument('power', type=int)
        self.args = self.parser.parse_args() 
Example #2
Source File: appinterface.py    From floranet with MIT License 6 votes vote down vote up
def __init__(self, **kwargs):
        self.restapi = kwargs['restapi']
        self.server = kwargs['server']
        self.fields = {
            'appif': fields.Integer,
            'name': fields.String,
        }
        self.parser = reqparse.RequestParser(bundle_errors=True)
        self.parser.add_argument('type', type=str)
        self.parser.add_argument('name', type=str)
        self.parser.add_argument('file', type=str)
        self.parser.add_argument('protocol', type=str)
        self.parser.add_argument('iothost', type=str)
        self.parser.add_argument('keyname', type=str)
        self.parser.add_argument('keyvalue', type=str)
        self.parser.add_argument('pollinterval', type=int)
        self.args = self.parser.parse_args() 
Example #3
Source File: appinterface.py    From floranet with MIT License 6 votes vote down vote up
def get(self):
        """Method to get all application interfaces"""
        try:
            interfaces = interfaceManager.getAllInterfaces()
            if interfaces is None:
                returnValue({})
            marshal_fields = {
                'type': fields.String(attribute='__class__.__name__'),
                'id': fields.Integer(attribute='appinterface.id'),
                'name': fields.String
            }
            data = {}
            for i,interface in enumerate(interfaces):
                data[i] = marshal(interface, marshal_fields)
            returnValue(data)
            yield
            
        except TimeoutError:
            log.error("REST API timeout retrieving application interfaces") 
Example #4
Source File: azure_iot_mqtt.py    From floranet with MIT License 6 votes vote down vote up
def marshal(self):
        """Get REST API marshalled fields as an orderedDict
        
        Returns:
            OrderedDict of fields defined by marshal_fields
        """
        marshal_fields = {
            'type': fields.String(attribute='__class__.__name__'),
            'id': fields.Integer(attribute='appinterface.id'),
            'name': fields.String,
            'iothost': fields.String,
            'keyname': fields.String,
            'keyvalue': fields.String,
            'started': fields.Boolean,
        }
        return marshal(self, marshal_fields) 
Example #5
Source File: azure_iot_https.py    From floranet with MIT License 6 votes vote down vote up
def marshal(self):
        """Get REST API marshalled fields as an orderedDict
        
        Returns:
            OrderedDict of fields defined by marshal_fields
        """
        marshal_fields = {
            'type': fields.String(attribute='__class__.__name__'),
            'id': fields.Integer(attribute='appinterface.id'),
            'name': fields.String,
            'iothost': fields.String,
            'keyname': fields.String,
            'keyvalue': fields.String,
            'poll_interval': fields.Integer,
            'started': fields.Boolean,
        }
        return marshal(self, marshal_fields) 
Example #6
Source File: __init__.py    From timesketch with Apache License 2.0 5 votes vote down vote up
def to_json(self,
                model,
                model_fields=None,
                meta=None,
                status_code=HTTP_STATUS_CODE_OK):
        """Create json response from a database models.

        Args:
            model: Instance of a timesketch database model
            model_fields: Dictionary describing the resulting schema
            meta: Dictionary holding any metadata for the result
            status_code: Integer used as status_code in the response

        Returns:
            Response in json format (instance of flask.wrappers.Response)
        """
        if not meta:
            meta = dict()

        schema = {'meta': meta, 'objects': []}

        if model:
            if not model_fields:
                try:
                    model_fields = self.fields_registry[model.__tablename__]
                except AttributeError:
                    model_fields = self.fields_registry[model[0].__tablename__]
            schema['objects'] = [marshal(model, model_fields)]

        response = jsonify(schema)
        response.status_code = status_code
        return response 
Example #7
Source File: system.py    From floranet with MIT License 5 votes vote down vote up
def __init__(self, **kwargs):
        self.restapi = kwargs['restapi']
        self.server = kwargs['server']
        self.fields = {
            'name': fields.String,
            'listen': fields.String,
            'port': fields.Integer,
            'webport': fields.Integer,
            'apitoken': fields.String,
            'freqband': fields.String,
            'netid': fields.Integer,
            'duplicateperiod': fields.Integer,
            'fcrelaxed': fields.Boolean,
            'otaastart': fields.Integer,
            'otaaend':  fields.Integer,
            'macqueueing': fields.Boolean,
            'macqueuelimit': fields.Integer,
            'adrenable': fields.Boolean,
            'adrmargin': fields.Float,
            'adrcycletime': fields.Integer,
            'adrmessagetime': fields.Integer,
        }
        self.parser = reqparse.RequestParser(bundle_errors=True)
        self.parser.add_argument('name', type=str)
        self.parser.add_argument('listen', type=str)
        self.parser.add_argument('port', type=int)
        self.parser.add_argument('webport', type=int)
        self.parser.add_argument('apitoken', type=str)
        self.parser.add_argument('freqband', type=str)
        self.parser.add_argument('netid', type=int)
        self.parser.add_argument('duplicateperiod', type=int)
        self.parser.add_argument('fcrelaxed', type=bool)
        self.parser.add_argument('otaastart', type=int)
        self.parser.add_argument('otaaend', type=int)
        self.parser.add_argument('macqueuing', type=bool)
        self.parser.add_argument('macqueuelimit', type=int)
        self.parser.add_argument('adrenable', type=bool)
        self.parser.add_argument('adrmargin', type=float)
        self.parser.add_argument('adrcycletime', type=int)
        self.parser.add_argument('adrmessagetime', type=int)
        self.args = self.parser.parse_args() 
Example #8
Source File: device.py    From floranet with MIT License 5 votes vote down vote up
def __init__(self, **kwargs):
        self.restapi = kwargs['restapi']
        self.server = kwargs['server']
        self.fields = {
            'deveui': fields.Integer,
            'name': fields.String,
            'devclass': fields.String,
            'enabled': fields.Boolean,
            'otaa': fields.Boolean,
            'devaddr': fields.Integer,
            'appeui': fields.Integer,
            'appskey': fields.Integer,
            'nwkskey': fields.Integer,
            'tx_datr': fields.String,
            'snr_average': fields.Float,
            'appname': fields.String,
            'latitude': fields.Float,
            'longitude': fields.Float,
            'created': fields.DateTime(dt_format='iso8601'),
            'updated': fields.DateTime(dt_format='iso8601')
        }
        self.parser = reqparse.RequestParser(bundle_errors=True)
        self.parser.add_argument('deveui', type=int)
        self.parser.add_argument('name', type=str)
        self.parser.add_argument('devclass', type=str)
        self.parser.add_argument('enabled', type=inputs.boolean)
        self.parser.add_argument('otaa', type=inputs.boolean)
        self.parser.add_argument('devaddr', type=int)
        self.parser.add_argument('appeui', type=int)
        self.parser.add_argument('nwkskey', type=int)
        self.parser.add_argument('appskey', type=int)
        self.parser.add_argument('appname', type=str)
        self.parser.add_argument('latitude', type=float)
        self.parser.add_argument('longitude', type=float)
        self.args = self.parser.parse_args() 
Example #9
Source File: application.py    From floranet with MIT License 5 votes vote down vote up
def __init__(self, **kwargs):
        self.restapi = kwargs['restapi']
        self.server = kwargs['server']
        self.fields = {
            'appeui': fields.Integer,
            'name': fields.String,
            'domain': fields.String,
            'appnonce': fields.Integer,
            'appkey': fields.Integer,
            'fport': fields.Integer,
            'appinterface_id': fields.Integer,
            'properties': {},
            'created': fields.DateTime(dt_format='iso8601'),
            'updated': fields.DateTime(dt_format='iso8601')
        }
        self.pfields = {
            'port': fields.Integer,
            'name': fields.String,
            'type': fields.String,
            'created': fields.DateTime(dt_format='iso8601'),
            'updated': fields.DateTime(dt_format='iso8601')
        }
        self.parser = reqparse.RequestParser(bundle_errors=True)
        self.parser.add_argument('appeui', type=int)
        self.parser.add_argument('name', type=str)
        self.parser.add_argument('domain', type=str)
        self.parser.add_argument('appnonce', type=int)
        self.parser.add_argument('appkey', type=int)
        self.parser.add_argument('fport', type=int)
        self.parser.add_argument('interface', type=int)
        self.args = self.parser.parse_args() 
Example #10
Source File: reflector.py    From floranet with MIT License 5 votes vote down vote up
def marshal(self):
        """Get REST API marshalled fields as an orderedDict
        
        Returns:
            OrderedDict of fields defined by marshal_fields
        """
        marshal_fields = {
            'type': fields.String(attribute='__class__.__name__'),
            'id': fields.Integer(attribute='appinterface.id'),
            'name': fields.String,
            'started': fields.Boolean
        }
        return marshal(self, marshal_fields) 
Example #11
Source File: file_text_store.py    From floranet with MIT License 5 votes vote down vote up
def marshal(self):
        """Get REST API marshalled fields as an orderedDict
        
        Returns:
            OrderedDict of fields defined by marshal_fields
        """
        marshal_fields = {
            'type': fields.String(attribute='__class__.__name__'),
            'id': fields.Integer(attribute='appinterface.id'),
            'name': fields.String,
            'file': fields.String,
            'started': fields.Boolean
        }
        return marshal(self, marshal_fields) 
Example #12
Source File: interactive.py    From pytorch-human-performance-gec with Apache License 2.0 4 votes vote down vote up
def listen_to_web(args, max_positions, task, process_batch):
    # initialize web app
    app = Flask(__name__, static_folder='')
    api = Api(app)

    # register route for web server

    # a simple form page
    @app.route('/form')
    def form():
        input = request.args.get('input', '')
        inputs = [input]
        results, outputs = process_inputs(args, inputs, max_positions, task, process_batch)
        return render_template('form.html', input=input, outputs=outputs)

    # a dynamic web app with static resource
    @app.route('/')
    def index():
        return render_template('index.html')

    @app.route('/static/<path:path>')
    def send_static(path):
        return send_from_directory('templates/static', path)

    # a JSON api
    resource_fields = {
        'iteration': fields.Integer,
        'src_str': fields.String, 'hypo_str': fields.String,
        'hypo_score': fields.Float, 'pos_scores': fields.Float, 'gleu_scores': fields.Float,
        'fluency_scores': fields.Float, 'alignments': fields.Float,
        'hypo_score_str': fields.String, 'pos_scores_str': fields.String, 'gleu_scores_str': fields.String,
        'fluency_scores_str': fields.String,  'alignments_str': fields.String
    }
    class API(Resource):
        @marshal_with(resource_fields)
        def get(self, input):
            inputs = [input]
            results, outputs = process_inputs(args, inputs, max_positions, task, process_batch)
            # return outputs # raw string outputs
            return results # json

    # register routes for API
    api.add_resource(API, '/api/<string:input>')

    # listen with web server
    print('server running at port: {}'.format(args.port))
    http_server = WSGIServer(('', args.port), app)
    http_server.serve_forever()