text
stringlengths
0
828
fields = [(field_name, attrs.pop(field_name)) for field_name, obj in attrs.items() if is_field(obj)]
# add fields from base classes:
for base in bases[::-1]:
if hasattr(base, 'base_fields'):
fields = base.base_fields.items() + fields
return dict(fields)"
4064,"def validate(self, data=None):
"""""" Validate the data
Check also that no extra properties are present.
:raises: ValidationError if the data is not valid.
""""""
errors = {}
data = self._getData(data)
# validate each field, one by one
for name, field in self.fields.items():
try:
field.clean(data.get(name))
except ValidationError, e:
errors[name] = e.messages
except AttributeError, e:
raise ValidationError('data should be of type dict but is %s' % (type(data),))
# check for extra fields
extras = set(data.keys()) - set(self.fields.keys())
if extras:
errors[', '.join(extras)] = ['field(s) not allowed']
# if errors, raise ValidationError
if errors:
raise ValidationError(errors)"
4065,"def _getData(self, data):
"""""" Check that data is acceptable and return it.
Default behavior is that the data has to be of type `dict`. In derived
classes this method could for example allow `None` or empty strings and
just return empty dictionary.
:raises: ``ValidationError`` if data is missing or wrong type
:return: the data to be validated
""""""
if not isinstance(data, dict):
raise ValidationError(
'data is not a valid dictionary: %s' % (str(type(data)),))
return data"
4066,"def lambda_handler(event, context):
""""""Main handler.""""""
users = boto3.resource(""dynamodb"").Table(os.environ['people'])
auth = check_auth(event, role=[""admin""])
if not auth['success']:
return auth
user_email = event.get('user_email', None)
if not user_email:
msg = ""Missing user_email parameter in your request.""
return {'success': False, 'message': msg}
user_role = event.get('user_role', None)
if not user_role:
msg = ""Missing user role: `admin`, `analyst`""
return {'success': False, 'message': msg}
user_name = event.get('user_name', '')
seed = random.randint(100000000, 999999999)
hash_key = ""{}{}"".format(user_email, seed)
api_key = hashlib.sha256(hash_key).hexdigest()
if auth.get('init', False):
user_role = 'admin'
else:
user_role = user_role
obj = {'email': user_email, 'name': user_name, 'api_key': api_key,
'role': user_role}
response = users.put_item(Item=obj)
return obj"
4067,"def get_connection(self, internal=False):
""""""Get a live connection to this instance.
:param bool internal: Whether or not to use a DC internal network connection.
:rtype: :py:class:`redis.client.StrictRedis`
""""""
# Determine the connection string to use.
connect_string = self.connect_string
if internal:
connect_string = self.internal_connect_string
# Stripe Redis protocol prefix coming from the API.
connect_string = connect_string.strip('redis://')
host, port = connect_string.split(':')
# Build and return the redis client.
return redis.StrictRedis(host=host, port=port, password=self._password)"
4068,"def get_cached(self, path, cache_name, **kwargs):
""""""Request a resource form the API, first checking if there is a cached
response available. Returns the parsed JSON data.
""""""
if gw2api.cache_dir and gw2api.cache_time and cache_name:
cache_file = os.path.join(gw2api.cache_dir, cache_name)