<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> from utils import base_url <EOL> import io <EOL> import json <EOL> import logging <EOL> from apiclient import errors <EOL> from apiclient . http import MediaIoBaseUpload <EOL> _BOUNDARY = "<STR_LIT>" <EOL> def _create_multipart_body ( metadata , content , contentType ) : <EOL> base64_data = content . encode ( "<STR_LIT>" ) . replace ( "<STR_LIT:\n>" , "<STR_LIT>" ) <EOL> multipart_body = "<STR_LIT>" + _BOUNDARY + "<STR_LIT:\r\n>" <EOL> multipart_body += "<STR_LIT>" <EOL> multipart_body += json . dumps ( metadata ) <EOL> multipart_body += "<STR_LIT>" + _BOUNDARY + "<STR_LIT:\r\n>" <EOL> multipart_body += "<STR_LIT>" + contentType + "<STR_LIT:\r\n>" <EOL> multipart_body += "<STR_LIT>" <EOL> multipart_body += base64_data <EOL> multipart_body += "<STR_LIT>" + _BOUNDARY + "<STR_LIT>" <EOL> return multipart_body <EOL> def multipart_insert ( metadata , content , contentType , service , test ) : <EOL> if metadata is None : <EOL> metadata = { } <EOL> """<STR_LIT>""" <EOL> if test is None : <EOL> media = MediaIoBaseUpload ( io . BytesIO ( content ) , contentType , resumable = True ) <EOL> try : <EOL> return service . timeline ( ) . insert ( body = metadata , media_body = media ) . execute ( ) <EOL> except errors . HttpError , error : <EOL> logging . error ( "<STR_LIT>" % error ) <EOL> return error <EOL> multipart_body = _create_multipart_body ( metadata , content , contentType ) <EOL> headers = { } <EOL> headers [ "<STR_LIT:Content-Type>" ] = "<STR_LIT>" + _BOUNDARY + "<STR_LIT>" <EOL> return service . _http . request ( base_url + "<STR_LIT>" , method = "<STR_LIT:POST>" , body = multipart_body , headers = headers ) <EOL> def multipart_update ( cardId , metadata , content , contentType , service , test ) : <EOL> if metadata is None : <EOL> metadata = { } <EOL> """<STR_LIT>""" <EOL> if test is None : <EOL> media = MediaIoBaseUpload ( io . BytesIO ( content ) , contentType , resumable = True ) <EOL> try : <EOL> return service . timeline ( ) . update ( id = cardId , body = metadata , media_body = media ) . execute ( ) <EOL> except errors . HttpError , error : <EOL> logging . error ( "<STR_LIT>" % error ) <EOL> return error <EOL> multipart_body = _create_multipart_body ( metadata , content , contentType ) <EOL> headers = { } <EOL> headers [ "<STR_LIT:Content-Type>" ] = "<STR_LIT>" + _BOUNDARY + "<STR_LIT>" <EOL> return service . _http . request ( "<STR_LIT>" % ( base_url , cardId ) , method = "<STR_LIT:POST>" , body = multipart_body , headers = headers ) <EOL> def media_insert ( cardId , content , contentType , service , test ) : <EOL> """<STR_LIT>""" <EOL> if test is None : <EOL> media = MediaIoBaseUpload ( io . BytesIO ( content ) , contentType , resumable = True ) <EOL> try : <EOL> return service . timeline ( ) . attachments ( ) . insert ( id = cardId , media_body = media ) . execute ( ) <EOL> except errors . HttpError , error : <EOL> logging . error ( "<STR_LIT>" % error ) <EOL> return error <EOL> multipart_body = _create_multipart_body ( { } , content , contentType ) <EOL> headers = { } <EOL> headers [ "<STR_LIT:Content-Type>" ] = "<STR_LIT>" + _BOUNDARY + "<STR_LIT>" <EOL> return service . _http . request ( "<STR_LIT>" % ( base_url , cardId ) , method = "<STR_LIT:POST>" , body = multipart_body , headers = headers ) </s>
