def post(self):
        #
        # Upload/create file
        #
        try:
            AWS_BUCKET     = self.app_settings('auth-s3', '\n', True).split('\n')[0]
            AWS_ACCESS_KEY = self.app_settings('auth-s3', '\n', True).split('\n')[1]
            AWS_SECRET_KEY = self.app_settings('auth-s3', '\n', True).split('\n')[2]
        except Exception, e:
            return self.json({
                'error': 'Amazon S3 bucket, key or secret not set!',
                'time': round(self.request.request_time(), 3),
            }, 400)

        if not self.current_user:
            return self.json({
                'error': 'Forbidden!',
                'time': round(self.request.request_time(), 3),
            }, 403)

        entity_id = self.get_argument('entity', default=None, strip=True)
        if not entity_id:
            return self.json({
                'error': 'No entity ID!',
                'time': round(self.request.request_time(), 3),
            }, 400)

        # entity = self.get_entities(entity_id=entity_id, limit=1)
        # if not entity:
        #     return self.json({
        #         'error': 'Entity with given ID is not found!',
        #         'time': round(self.request.request_time(), 3),
        #     }, 404)

        property_definition_keyname = self.get_argument('property', default=None, strip=True)
        if not property_definition_keyname:
            return self.json({
                'error': 'No property!',
                'time': round(self.request.request_time(), 3),
            }, 400)

        filename = self.get_argument('filename', default=None, strip=True)
        if not filename:
            return self.json({
                'error': 'No filename!',
                'time': round(self.request.request_time(), 3),
            }, 400)

        filetype = self.get_argument('filetype', None, True)
        if not filetype:
            filetype = 'binary/octet-stream'

        filesize = self.get_argument('filesize', 0, True)
        if int(filesize) > 4294967295:
            return self.json({
                'error': 'Max file size is 4294967295 bytes!',
                'time': round(self.request.request_time(), 3),
            }, 400)

        key = '%s_2/%s' % (self.app_settings('database-name'), entity_id)

        new_property_id = self.set_property(entity_id=entity_id, property_definition_keyname=property_definition_keyname, value={'filename': filename, 's3key': key, 'filesize': filesize})
        if new_property_id:
            properties = {property_definition_keyname: [{'id': new_property_id, 'value': filename}]}
        else:
            properties = None

        key = (key, new_property_id) % '%s/%s'

        policy = {
            'expiration': (datetime.datetime.utcnow()+datetime.timedelta(hours=1)).strftime('%Y-%m-%dT%H:%M:%SZ'),
            'conditions': [
                {'bucket': AWS_BUCKET},
                ['starts-with', '$key', key],
                {'acl': 'private'},
                {'success_action_status': '201'},
                {'x-amz-server-side-encryption': 'AES256'},
                {'Content-Type': filetype},
                ['starts-with', '$Content-Disposition', 'inline; filename'],
            ]
        }
        encoded_policy = json.dumps(policy).encode('utf-8').encode('base64').replace('\n','')
        signature = hmac.new(str(AWS_SECRET_KEY), str(encoded_policy), sha1).digest().encode('base64').replace('\n','')

        self.json({
            'result': {
                'id': entity_id,
                'properties': properties,
                's3': {
                    'url': 'https://%s.s3.amazonaws.com/' % AWS_BUCKET,
                    'data': {
                        'key':                          key,
                        'acl':                          'private',
                        'success_action_status':        '201',
                        'x-amz-server-side-encryption': 'AES256',
                        'AWSAccessKeyId':               AWS_ACCESS_KEY,
                        'policy':                       encoded_policy,
                        'signature':                    signature,
                        'Content-Type':                 filetype,
                        'Content-Disposition':          'inline; filename*=UTF-8\'\'%s' % urllib.quote(filename.encode('utf-8')),
                    }
                }
            },
            'time': round(self.request.request_time(), 3),
        })
dataset/ETHPy150Open argoroots/Entu/app/api/api2.py/API2AmazonFileUpload.post/swapped operands of `%`