def convert(self, value, op): # Don't cast None if value is None: if not self.nullable: raise ValueError("Must not be null!") return None elif isinstance(self.type, Model) and isinstance(value, dict): return marshal(value, self.type) # and check if we're expecting a filestorage and haven't overridden `type` # (required because the below instantiation isn't valid for FileStorage) elif isinstance(value, FileStorage) and self.type == FileStorage: return value try: return self.type(value, self.name, op) except TypeError: try: if self.type is decimal.Decimal: return self.type(str(value), self.name) else: return self.type(value, self.name) except TypeError: return self.type(value)
def get(self, user_type=None, uid=None, xchat_uid=None): """获取用户基本信息""" customer = current_customer app = customer.app if xchat_uid is not None: ns, app_uid = xchat_biz.decode_ns_user(xchat_uid) res, parts = app_biz.parse_app_uid(app_uid) if res: app_name, user_type, uid = parts if app_name != app.name: return abort(404, 'app user not found') else: return abort(404, 'app user not found') if user_type is not None: if user_type == UserType.customer: customer = app.customers.filter_by(uid=uid).one() return marshal(customer, app_customer) elif user_type == UserType.staff: staff = app.staffs.filter_by(uid=uid).one() return marshal(staff, app_staff) return abort(404, 'app user not found') return abort(404, 'app user not found')
def post(self): args = reqparser.parse_args() content_type = args.content_type # TODO: Verify/Authorize the user for the turtle file if content_type == 'application/json': entities = marshal(args, entities_model)['entities'] entities = self.add_entities_json(entities) elif content_type == 'text/turtle': raise exceptions.NotImplemented( 'TODO: Implement entities addition for Content-Type {0}.'. format(content_type)) raw_ttl = request.data.decode('utf-8') self.add_entities_ttl(raw_ttl) else: raise exceptions.NotImplemented( 'TODO: Implement entities addition for Content-Type {0}.'. format(content_type)) return {'entities': entities}, 201
def __expand_json(js): res = {} for entry in js: # /!\ after marshalling, 'fullname' will be 'key' res[entry['fullname']] = marshal(entry, node_fields) return res
def get(self, server=None, name=None, backup=None): """Returns a list of 'nodes' under a given path **GET** method provided by the webservice. The *JSON* returned is: :: [ { "date": "2015-05-21 14:54:49", "gid": "0", "inodes": "173", "selected": false, "expanded": false, "children": [], "mode": "drwxr-xr-x", "name": "/", "key": "/", "title": "/", "fullname": "/", "parent": "", "size": "12.0KiB", "type": "d", "uid": "0" } ] The output is filtered by the :mod:`burpui.misc.acl` module so that you only see stats about the clients you are authorized to. :param server: Which server to collect data from when in multi-agent mode :type server: str :param name: The client we are working on :type name: str :param backup: The backup we are working on :type backup: int :returns: The *JSON* described above. """ args = self.parser.parse_args() server = server or args['serverName'] json = [] if not name or not backup: return json root_list = sorted(args['root']) if args['root'] else [] root_loaded = False paths_loaded = [] to_select_list = [] if not current_user.is_anonymous and \ not current_user.acl.is_admin() and \ not current_user.acl.is_client_allowed(name, server): self.abort(403, 'Sorry, you are not allowed to view this client') try: root_list_clean = [] for root in root_list: if args['recursive']: path = '' # fetch the root first if not already loaded if not root_loaded: part = bui.client.get_tree(name, backup, level=0, agent=server) root_loaded = True else: part = [] root = root.rstrip('/') to_select = root.rsplit('/', 1) if not to_select[0]: to_select[0] = '/' if len(to_select) == 1: # special case we want to select '/' to_select = ('', '/') if not root: root = '/' to_select_list.append(to_select) root_list_clean.append(root) paths = root.split('/') for level, sub in enumerate(paths, start=1): path = os.path.join(path, sub) if not path: path = '/' if path in paths_loaded: continue temp = bui.client.get_tree(name, backup, path, level, agent=server) paths_loaded.append(path) part += temp else: part = bui.client.get_tree(name, backup, root, agent=server) json += part if args['selected']: for entry in json: for parent, fold in to_select_list: if entry['parent'] == parent and entry['name'] == fold: entry['selected'] = True break if entry['parent'] in root_list_clean: entry['selected'] = True if not root_list: json = bui.client.get_tree(name, backup, agent=server) if args['selected']: for entry in json: if not entry['parent']: entry['selected'] = True if args['recursive']: tree = {} rjson = [] roots = [] for entry in json: # /!\ after marshalling, 'fullname' will be 'key' tree[entry['fullname']] = marshal(entry, node_fields) for key, entry in iteritems(tree): parent = entry['parent'] if not entry['children']: entry['children'] = None if parent: node = tree[parent] if not node['children']: node['children'] = [] node['children'].append(entry) if node['folder']: node['lazy'] = False node['expanded'] = True else: roots.append(entry['key']) for fullname in roots: rjson.append(tree[fullname]) json = rjson else: for entry in json: entry['children'] = None if not entry['folder']: entry['lazy'] = False except BUIserverException as e: self.abort(500, str(e)) return json
def get(self): items = item_service.get_all_items() if len(items) == 0: return {'status': 'no items found'}, 404 return marshal(items, item)
def get(self): users = user_service.get_all_users() if len(users) == 0: return {'status': 'no items found'}, 404 return marshal(users, user)
def get(self, server=None, name=None, backup=None): """Returns a list of 'nodes' under a given path **GET** method provided by the webservice. The *JSON* returned is: :: [ { "date": "2015-05-21 14:54:49", "gid": "0", "inodes": "173", "selected": false, "expanded": false, "children": [], "mode": "drwxr-xr-x", "name": "/", "key": "/", "title": "/", "fullname": "/", "parent": "", "size": "12.0KiB", "type": "d", "uid": "0" } ] The output is filtered by the :mod:`burpui.misc.acl` module so that you only see stats about the clients you are authorized to. :param server: Which server to collect data from when in multi-agent mode :type server: str :param name: The client we are working on :type name: str :param backup: The backup we are working on :type backup: int :returns: The *JSON* described above. """ args = self.parser.parse_args() server = server or args['serverName'] json = [] if not name or not backup: return json root_list = sorted(args['root']) if args['root'] else [] root_loaded = False paths_loaded = [] to_select_list = [] if (api.bui.acl and (not self.is_admin and not api.bui.acl.is_client_allowed(self.username, name, server))): self.abort(403, 'Sorry, you are not allowed to view this client') try: root_list_clean = [] for root in root_list: if args['recursive']: path = '' # fetch the root first if not already loaded if not root_loaded: part = api.bui.cli.get_tree( name, backup, level=0, agent=server ) root_loaded = True else: part = [] root = root.rstrip('/') to_select = root.rsplit('/', 1) if not to_select[0]: to_select[0] = '/' if len(to_select) == 1: # special case we want to select '/' to_select = ('', '/') if not root: root = '/' to_select_list.append(to_select) root_list_clean.append(root) paths = root.split('/') for level, sub in enumerate(paths, start=1): path = os.path.join(path, sub) if not path: path = '/' if path in paths_loaded: continue temp = api.bui.cli.get_tree( name, backup, path, level, agent=server ) paths_loaded.append(path) part += temp else: part = api.bui.cli.get_tree( name, backup, root, agent=server ) json += part if args['selected']: for entry in json: for parent, fold in to_select_list: if entry['parent'] == parent and entry['name'] == fold: entry['selected'] = True break if entry['parent'] in root_list_clean: entry['selected'] = True if not root_list: json = api.bui.cli.get_tree(name, backup, agent=server) if args['selected']: for entry in json: if not entry['parent']: entry['selected'] = True if args['recursive']: tree = {} rjson = [] roots = [] for entry in json: # /!\ after marshalling, 'fullname' will be 'key' tree[entry['fullname']] = marshal(entry, self.node_fields) for key, entry in tree.iteritems(): parent = entry['parent'] if not entry['children']: entry['children'] = None if parent: node = tree[parent] if not node['children']: node['children'] = [] node['children'].append(entry) if node['folder']: node['lazy'] = False node['expanded'] = True else: roots.append(entry['key']) for fullname in roots: rjson.append(tree[fullname]) json = rjson else: for entry in json: entry['children'] = None if not entry['folder']: entry['lazy'] = False except BUIserverException as e: self.abort(500, str(e)) return json
def get(self): notes = note_service.get_all_notes() print(len(notes)) if len(notes) == 0: return {'status': 'no notes found'}, 404 return marshal(notes, note)
def get(self): review_list = review.service.return_all_review() if len(review_list) == 0: return {"status": "no review files have been found"}, 404 return marshal(review_list, review)
def get(self): reviews = review_service.get_all_reviews() if len(reviews) == 0: return {'status': 'no reviews found'}, 404 return marshal(reviews, review)
def get(self): tcs_list = tcs.service.return_all_tcs() if len(tcs_list) == 0: return {"status": "no tcs files have been found"}, 404 return marshal(tcs_list, tcs)
def get(self): tcs_country_filtered_list = tcs.service.return_tcs_of_country() if len(tcs_country_filtered_list) == 0: return {"status": "no tcs files have been found"}, 404 return marshal(tcs_country_filtered_list, tcs)