MCPcopy Create free account
hub / github.com/O365/python-o365 / Storage

Class Storage

O365/drive.py:1831–1934  ·  view source on GitHub ↗

Parent Class that holds drives

Source from the content-addressed store, hash-verified

1829
1830
1831class Storage(ApiComponent):
1832 """ Parent Class that holds drives """
1833
1834 _endpoints = {
1835 'default_drive': '/drive',
1836 'get_drive': '/drives/{id}',
1837 'list_drives': '/drives',
1838 }
1839 drive_constructor = Drive
1840
1841 def __init__(self, *, parent=None, con=None, **kwargs):
1842 """ Create a storage representation
1843
1844 :param parent: parent for this operation
1845 :type parent: Account
1846 :param Connection con: connection to use if no parent specified
1847 :param Protocol protocol: protocol to use if no parent specified
1848 (kwargs)
1849 :param str main_resource: use this resource instead of parent resource
1850 (kwargs)
1851 """
1852 if parent and con:
1853 raise ValueError('Need a parent or a connection but not both')
1854 self.con = parent.con if parent else con
1855
1856 # Choose the main_resource passed in kwargs over parent main_resource
1857 main_resource = kwargs.pop('main_resource', None) or (
1858 getattr(parent, 'main_resource', None) if parent else None)
1859 super().__init__(
1860 protocol=parent.protocol if parent else kwargs.get('protocol'),
1861 main_resource=main_resource)
1862
1863 def __str__(self):
1864 return self.__repr__()
1865
1866 def __repr__(self):
1867 return 'Storage for resource: {}'.format(self.main_resource)
1868
1869 def get_default_drive(self, request_drive=False):
1870 """ Returns a Drive instance
1871
1872 :param request_drive: True will make an api call to retrieve the drive
1873 data
1874 :return: default One Drive
1875 :rtype: Drive
1876 """
1877 if request_drive is False:
1878 return Drive(con=self.con, protocol=self.protocol,
1879 main_resource=self.main_resource, name='Default Drive')
1880
1881 url = self.build_url(self._endpoints.get('default_drive'))
1882
1883 response = self.con.get(url)
1884 if not response:
1885 return None
1886
1887 drive = response.json()
1888

Callers 2

storageMethod · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected