def validate_updated_info(self, dic):
     print "check"
     for key in dic:
         if key not in user_info.user_info_structure:
             raise errors.IncorrectRequestData()
         if key in user_info.USER_INFO_VAL_OBJECT_KEYS:
             for nested_key in dic[key]:
                 if nested_key not in user_info.value_object:
                     logger.error("Incorrect update info request data.")
                     logger.error("Invalid key : %s", nested_key)
                     raise errors.IncorrectRequestData()
     logger.info("Update info object validated for user %s",
                 current_user.get_id())
     return
class BaseCommunicator:
    ___metaclass__ = ABCMeta

    @abstractmethod
    def __init__(self):
        """On init, simply initialize auth flow"""
        self.auth = auth.AuthHelper()

    @abstractmethod
    def get_ip(self, req):
        return req.access_route[0]

    @abstractmethod
    def check_auth(self, input_data, req):
        # TODO
        return True

    @abstractmethod
    def get_request_data(self, req):
        """Common functionality of unmarshalling input data needed for all"""
        raw_data = req.get_data()
        try:
            str_data = urllib.unquote_plus(raw_data).decode('utf-8')
        except Exception, decode_err:
            logger.error("Error in decoding request data %s", str(decode_err))
            raise errors.IncorrectRequestData()
        # Convert the data to json.
        try:
            input_data = json.loads(str_data)
        except ValueError, json_err:
            logger.error("Error in converting input data to json %s",
                         str(json_err))
            raise errors.IncorrectRequestData()
 def get_request_data(self, req):
     """Common functionality of unmarshalling input data needed for all"""
     raw_data = req.get_data()
     try:
         str_data = urllib.unquote_plus(raw_data).decode('utf-8')
     except Exception, decode_err:
         logger.error("Error in decoding request data %s", str(decode_err))
         raise errors.IncorrectRequestData()
 def __init__(self, inputData):
     """Expects input_data to be a map containing required keys."""
     self.info_dict = None
     try:
         data = inputData["data"]
         updated_info = data["user_info"]
         updated_info = dict(
             (k, v) for k, v in updated_info.iteritems() if v)
         # Validate info keys in request
         self.validate_updated_info(updated_info)
         self.info_dict = updated_info
     except errors.IncorrectRequestData, err:
         logger.error("Input data does not have correct attributes")
         logger.error("%s", err)
         raise errors.IncorrectRequestData()