labpack/messaging/telegram.py
def _get_data(self, file_url, file_name='', method_title='', argument_title=''):

        ''' a helper method to retrieve data buffer for a file url

        :param file_url: string with url to file
        :param file_name: [optional] string with name to affix to file buffer
        :param method_title: [optional] string with name of class method calling
        :param argument_title: [optional] string with name of method argument key
        :return: byte data buffer with file data
        '''

        # https://docs.python.org/3/library/io.html#io.BytesIO

        import io
        import requests

    # fill empty values
        if not file_name:
            file_name = 'file'
        if not method_title:
            method_title = '%s._get_data' % self.__class__.__name__
        if not argument_title:
            argument_title = 'file_url'

    # request file from url
        try:
            remote_file = requests.get(file_url)
        except requests.exceptions.ConnectionError as err:
            if self.requests_handler:
                return self.requests_handler(err)
            else:
                raise
        except:
            raise ValueError('%s(%s=%s) is not a valid url.' % (method_title, argument_title, file_url))

    # add contents to buffer
        file_buffer = io.BytesIO(remote_file.content)
        file_buffer.name = '%s' % file_name

        return file_buffer
 a helper method to retrieve data buffer for a file url

        :param file_url: string with url to file
        :param file_name: [optional] string with name to affix to file buffer
        :param method_title: [optional] string with name of class method calling
        :param argument_title: [optional] string with name of method argument key
        :return: byte data buffer with file data
        
a helper method to retrieve data buffer for a file url
a helper method to retrieve data buffer for a file url
def _get_data(self, file_url, file_name='', method_title='', argument_title=''):
        import io
        import requests
        if not file_name:
            file_name = 'file'
        if not method_title:
            method_title = '%s._get_data' % self.__class__.__name__
        if not argument_title:
            argument_title = 'file_url'
        try:
            remote_file = requests.get(file_url)
        except requests.exceptions.ConnectionError as err:
            if self.requests_handler:
                return self.requests_handler(err)
            else:
                raise
        except:
            raise ValueError('%s(%s=%s) is not a valid url.' % (method_title, argument_title, file_url))
        file_buffer = io.BytesIO(remote_file.content)
        file_buffer.name = '%s' % file_name
        return file_buffer
def _get_data ( self , file_url , file_name = '' , method_title = '' , argument_title = '' ) : import io import requests if not file_name : file_name = 'file' if not method_title : method_title = '%s._get_data' % self . __class__ . __name__ if not argument_title : argument_title = 'file_url' try : remote_file = requests . get ( file_url ) except requests . exceptions . ConnectionError as err : if self . requests_handler : return self . requests_handler ( err ) else : raise except : raise ValueError ( '%s(%s=%s) is not a valid url.' % ( method_title , argument_title , file_url ) ) file_buffer = io . BytesIO ( remote_file . content ) file_buffer . name = '%s' % file_name return file_buffer
a helper method to retrieve data buffer for a file url
a helper method to retrieve data buffer for a file url
''' a helper method to retrieve data buffer for a file url

        :param file_url: string with url to file
        :param file_name: [optional] string with name to affix to file buffer
        :param method_title: [optional] string with name of class method calling
        :param argument_title: [optional] string with name of method argument key
        :return: byte data buffer with file data
        ''' # https://docs.python.org/3/library/io.html#io.BytesIO
 # fill empty values
 # request file from url
 # add contents to buffer

byte data buffer with file data
byte data buffer with file data
self
file_url
string with url to file
string with url to file
file_name
[optional] string with name to affix to file buffer
[ optional ] string with name to affix to file buffer
method_title
[optional] string with name of class method calling
[ optional ] string with name of class method calling
argument_title
[optional] string with name of method argument key
[ optional ] string with name of method argument key