How to use the aiogoogle.utils._safe_getitem function in aiogoogle

To help you get started, we’ve selected a few aiogoogle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github omarryhan / aiogoogle / aiogoogle / method.py View on Github external
def _build_resumeable_media(self, upload_file):
            resumable_upload_path = _safe_getitem(self._method_specs, 'mediaUpload', 'protocols', 'resumable', 'path') or ''
            resumable_url = self._root_url[:-1] + resumable_upload_path
            multipart = self.mediaUpload['protocols']['resumable'].get('multipart', False)
            return ResumableUpload(upload_file, multipart=multipart, upload_path=resumable_url)
github omarryhan / aiogoogle / aiogoogle / resource.py View on Github external
self._build_resumeable_media(upload_file, qualified_url)
            if _safe_getitem(
                self._method_specs, "mediaUpload", "protocols", "resumable"
            )
            else None
        )

        # Create MediaUpload object and pass it the resumable object we just created
        # simple_upload_path = _safe_getitem(self._method_specs, 'mediaUpload', 'protocols', 'simple', 'path')
        # media_upload_url_base = self._root_url[:-1] + simple_upload_path
        media_upload_url_base = self._root_url + "upload/" + self._service_path
        media_upload_url = qualified_url.replace(self._base_url, media_upload_url_base)
        max_size = self._convert_str_size_to_int(
            _safe_getitem(self._method_specs, "mediaUpload", "maxSize")
        )
        mime_range = _safe_getitem(self._method_specs, "mediaUpload", "accept")
        multipart = self["mediaUpload"]["protocols"]["simple"].get("multipart", True)

        return MediaUpload(
            file_path=upload_file,
            upload_path=media_upload_url,
            max_size=max_size,
            mime_range=mime_range,
            multipart=multipart,
            resumable=resumable,
            validate=validate,
        )
github omarryhan / aiogoogle / aiogoogle / method.py View on Github external
def _validate_body(self, req):
        request_schema = self._method_specs.get('request')
        if request_schema is not None:

            # If there's a reference resolve
            if '$ref' in request_schema:
                request_schema = self._schemas.get('$ref')
            
            # Check if request schema isn't not from the previous step
            if request_schema is not None:
                
                # Iterate over req and validate every param passed in req
                for k,v in req.items():

                    sub_schema_to_check_against = _safe_getitem(request_schema, 'properties', k)
                    
                    if sub_schema_to_check_against:

                        self._validate(v, sub_schema_to_check_against)
github omarryhan / aiogoogle / aiogoogle / resource.py View on Github external
# If resumable, create resumable object
        resumable = (
            self._build_resumeable_media(upload_file, qualified_url)
            if _safe_getitem(
                self._method_specs, "mediaUpload", "protocols", "resumable"
            )
            else None
        )

        # Create MediaUpload object and pass it the resumable object we just created
        # simple_upload_path = _safe_getitem(self._method_specs, 'mediaUpload', 'protocols', 'simple', 'path')
        # media_upload_url_base = self._root_url[:-1] + simple_upload_path
        media_upload_url_base = self._root_url + "upload/" + self._service_path
        media_upload_url = qualified_url.replace(self._base_url, media_upload_url_base)
        max_size = self._convert_str_size_to_int(
            _safe_getitem(self._method_specs, "mediaUpload", "maxSize")
        )
        mime_range = _safe_getitem(self._method_specs, "mediaUpload", "accept")
        multipart = self["mediaUpload"]["protocols"]["simple"].get("multipart", True)

        return MediaUpload(
            file_path=upload_file,
            upload_path=media_upload_url,
            max_size=max_size,
            mime_range=mime_range,
            multipart=multipart,
            resumable=resumable,
            validate=validate,
        )
github omarryhan / aiogoogle / aiogoogle / method.py View on Github external
def _build_upload_media(self, upload_file):
        # Check if method supports media upload
        # Will check wether validate is true or false
        if self._method_specs.get('supportsMediaUpload') is not True:
            raise ValidationError('upload_file was provided while method doesn\'t support media upload')
        
        # If resumable, create resumable object
        resumable = self._build_resumeable_media(upload_file) if _safe_getitem(self._method_specs, 'mediaUpload', 'protocols', 'resumable') else None
        
        # Create MediaUpload object and pass it the resumable object we just created
        simple_upload_path = _safe_getitem(self._method_specs, 'mediaUpload', 'protocols', 'simple', 'path') or ''
        if simple_upload_path:
            media_upload_url = self._root_url[:-1] + simple_upload_path
        else:
            media_upload_url = None 
        mime_range = _safe_getitem(self._method_specs, 'mediaUpload', 'accept')
        multipart = self.mediaUpload['protocols']['simple'].get('multipart', False)

        # Return
        return MediaUpload(upload_file, upload_path=media_upload_url, mime_range=mime_range, multipart=multipart, resumable=resumable)
github omarryhan / aiogoogle / aiogoogle / method.py View on Github external
def _build_upload_media(self, upload_file):
        # Check if method supports media upload
        # Will check wether validate is true or false
        if self._method_specs.get('supportsMediaUpload') is not True:
            raise ValidationError('upload_file was provided while method doesn\'t support media upload')
        
        # If resumable, create resumable object
        resumable = self._build_resumeable_media(upload_file) if _safe_getitem(self._method_specs, 'mediaUpload', 'protocols', 'resumable') else None
        
        # Create MediaUpload object and pass it the resumable object we just created
        simple_upload_path = _safe_getitem(self._method_specs, 'mediaUpload', 'protocols', 'simple', 'path') or ''
        if simple_upload_path:
            media_upload_url = self._root_url[:-1] + simple_upload_path
        else:
            media_upload_url = None 
        mime_range = _safe_getitem(self._method_specs, 'mediaUpload', 'accept')
        multipart = self.mediaUpload['protocols']['simple'].get('multipart', False)

        # Return
        return MediaUpload(upload_file, upload_path=media_upload_url, mime_range=mime_range, multipart=multipart, resumable=resumable)