# Path: pyston/exception.py
# class RestException(Exception):
#     message = None
# 
#     def __init__(self, message=None):
#         super().__init__()
#         self.message = message or self.message
# 
#     @property
#     def errors(self):
#         return {'error': self.message}
# 
# Path: pyston/requested_fields/parser.py
# class DefaultRequestedFieldsParser:
#     """
#     Default fields parserr.
#     E.q.:
#         /api/user?_filter=first_name,last_name,issues(id)
#     """
# 
#     def parse(self, request):
#         input = request._rest_context.get('fields')
#         if input is None:
#             return None
#         return RFS.create_from_string(input)


from pyston.exception import RestException
from .parser import DefaultRequestedFieldsParser



class ModelRequestedFieldsManager:

    parser = None

    def get_requested_fields(self, resource, request):
        try:
            parsed_requested_rfs = self.parser.parse(request)
            if parsed_requested_rfs is None:
                return None
            else:
                return parsed_requested_rfs
        except RestException as ex:

# Path: pyston/exception.py
# class RestException(Exception):
#     message = None
# 
#     def __init__(self, message=None):
#         super().__init__()
#         self.message = message or self.message
# 
#     @property
#     def errors(self):
#         return {'error': self.message}
# 
# Path: pyston/requested_fields/parser.py
# class DefaultRequestedFieldsParser:
#     """
#     Default fields parserr.
#     E.q.:
#         /api/user?_filter=first_name,last_name,issues(id)
#     """
# 
#     def parse(self, request):
#         input = request._rest_context.get('fields')
#         if input is None:
#             return None
#         return RFS.create_from_string(input)


# Path: pyston/requested_fields/managers.py
from pyston.exception import RestException
from .parser import DefaultRequestedFieldsParser




class ModelRequestedFieldsManager:

    parser = None

    def get_requested_fields(self, resource, request):
        try:
            parsed_requested_rfs = self.parser.parse(request)
            if parsed_requested_rfs is None:
                return None
            else:
                return parsed_requested_rfs
        except RestException as ex:

            raise RestException(ex)