def GET(self, x_coord, y_coord, plant_id): if not x_coord: return models.Error().asXML("1", "No X coord specified") if not y_coord: return models.Error().asXML("2", "No Y coord specified") if not plant_id: return models.Error().asXML("3", "Unknown Plant") if not self.broker.seedPlant(x_coord, y_coord, plant_id): return models.Error().asXML( "4", "Can't seed plant at specified coords") return self.broker.getField().toxml()
def GET(self, x_coord, y_coord): if not y_coord: y_coord = None if not self.broker.digPlant(x_coord, y_coord): return models.Error().asXML( "5", "Can't dig. No plant or plant is not grown up") else: return self.broker.getField().toxml()
def add_error(message, dst_site, src_site, failure_type, amount, category_id=None): error = models.Error(message=message, dst_site=dst_site, src_site=src_site, amount=amount, category_id=category_id) if failure_type in ['transfer-failure', 'deletion-failure']: error.failure_type = failure_type else: raise Exception('The given failure type: %s, is not a valid failure type, valid types are "deletion-failure" and "transfer_failure"' % failure_type) if not isinstance(amount, int): raise Exception('the value for the amount column must be an integer, the value given was: %s' % amount) if category_id is not None and session.query(models.Error_category).filter_by(id=category_id).scalar() is None: raise Exception('The given category ID: %i, does not match any error_category row.' % category_id) if category_id is None: rows = session.query(models.Error_category).all() matching_ratio = 0.0 category_id = 0 matched = False for index, row in enumerate(rows): ratio = quick_match(message, row.regular_expression) if ratio > 0.95 and ratio > matching_ratio: matching_ratio = ratio category_id = row.id print('a match was found with match ratio: %f' % matching_ratio) print(message + '\n' + row.regular_expression) if index == len(rows) - 1 and matching_ratio > 0.95: if row.total_amount is None: row.total_amount = amount else: row.total_amount += amount error.category_id = category_id matched = True if matched is False: print('new error_category being added') ec = loads(add_error_category(message)) error.category_id = ec['id'] session.add(error) session.commit() return dumps(row2dict(error))
def GET(self, plant_id, state_id=None): cType = { "png": "images/png", "jpg": "image/jpeg", "gif": "image/gif", "ico": "image/x-icon" } if not plant_id: # background image requested sprite_name, image = self.broker.getBackgroundImage() else: sprite_name, image = self.broker.getPlantImage(plant_id, state_id) if not (sprite_name or image): return models.Error().asXML("6", "No Image for plant") ext = sprite_name.split('.')[-1] # get extension web.header("Content-Type", cType[ext]) # Set the Header return image
def nickname_available(self): self.mock_user.get.side_effect = models.Error() self.mock_user.exists.return_value = False