def post(self): args = self.validate_post() if args.method == 'facebook' or args.method == 'twitter': args.public = False else: args.public = boolify(args.get('public')) args.optIn = boolify(args.get('optIn')) args.created = datetime.now(tz=tzutc()) db = get_db() db.dares.insert_one(args) return two_oh_one()
def handle(self): data = self.request[0].strip() if sys.version_info >= (3, ): data = self.request[0].strip().decode("utf-8") logger.debug("EVENT: {0} from {1}".format(repr(data), self.client_address[0])) try: # Event Format <TIMESTAMP> <TYPE> <DETAIL> ts, key, value = data.split(" ", 2) except ValueError: logger.warn("Invalid Event Format {0}".format(data)) return data_dict = {} try: # Format key=value;key=value data_dict = dict(x.split('=') for x in value.split(';')) except ValueError: logger.warn("Unable to parse Event {0}".format(data)) return for k, v in data_dict.items(): try: if k in AUTO_BOOL_ATTRIBUTES: data_dict[k] = boolify(v) if k in AUTO_INT_ATTRIBUTES: data_dict[k] = int(v) except ValueError: # Auto Conversion failed, Retain the old value continue try: # Event Type to Function Map, Received event data will be in # the form <TIMESTAMP> <TYPE> <DETAIL>, Get Event name for the # received Type/Key and construct a function name starting with # handle_ For example: handle_event_volume_create func_name = "handle_" + all_events[int(key)].lower() except IndexError: # This type of Event is not handled? logger.warn("Unhandled Event: {0}".format(key)) func_name = None if func_name is not None: # Get function from handlers module func = getattr(handlers, func_name, None) # If func is None, then handler unimplemented for that event. if func is not None: func(ts, int(key), data_dict) else: # Generic handler, broadcast whatever received handlers.generic_handler(ts, int(key), data_dict)
def handle(self): data = self.request[0].strip() logger.debug("EVENT: {0} from {1}".format(repr(data), self.client_address[0])) try: # Event Format <TIMESTAMP> <TYPE> <DETAIL> ts, key, value = data.split(" ", 2) except ValueError: logger.warn("Invalid Event Format {0}".format(data)) return data_dict = {} try: # Format key=value;key=value data_dict = dict(x.split('=') for x in value.split(';')) except ValueError: logger.warn("Unable to parse Event {0}".format(data)) return for k, v in data_dict.iteritems(): try: if k in AUTO_BOOL_ATTRIBUTES: data_dict[k] = boolify(v) if k in AUTO_INT_ATTRIBUTES: data_dict[k] = int(v) except ValueError: # Auto Conversion failed, Retain the old value continue try: # Event Type to Function Map, Received event data will be in # the form <TIMESTAMP> <TYPE> <DETAIL>, Get Event name for the # received Type/Key and construct a function name starting with # handle_ For example: handle_event_volume_create func_name = "handle_" + all_events[int(key)].lower() except IndexError: # This type of Event is not handled? logger.warn("Unhandled Event: {0}".format(key)) func_name = None if func_name is not None: # Get function from handlers module func = getattr(handlers, func_name, None) # If func is None, then handler unimplemented for that event. if func is not None: func(ts, int(key), data_dict) else: # Generic handler, broadcast whatever received handlers.generic_handler(ts, int(key), data_dict)
def api_volume_options_get(name): opt = boolify(request.args.get("option", "all")) return gluster_cmd_to_http_response(volume.optget, name, opt)
def api_volume_get(name=None): status = boolify(request.args.get("status", "0")) if status: return gluster_cmd_to_http_response(volume.status_detail, name) else: return gluster_cmd_to_http_response(volume.info, name)
def api_volume_delete(name): force = boolify(request.form.get("force", "0")) return gluster_cmd_to_http_response(volume.stop, name, force=force)