def read_file(self, object_tree_folder, path, size, offset): log.debug('read_file: {}, {}, {}'.format( util.string_from_path_elements(path), size, offset)) if self._is_readme_file(path): return self._get_readme_text(size, offset) if len(path) <= 2: raise onedrive_exceptions.PathException('Invalid file') return self._resource_map_resolver.read_file(path[2:], size, offset)
def read_file(self, object_tree_root, path, size, offset): log.debug("read_file: {}, {}, {}".format( util.string_from_path_elements(path), size, offset)) if not path: raise onedrive_exceptions.PathException("Invalid file") if self._is_readme_file(path): return self._get_readme_text(size, offset) return self._resource_map_resolver.read_file(object_tree_root, path, size, offset)
def _validate_and_split_decade_range(self, decade): try: first_year, last_year = decade.split('-') if len(first_year) != 4 or len(last_year) != 4: raise ValueError first_year, last_year = int(first_year), int(last_year) if first_year > last_year: raise ValueError except ValueError: raise onedrive_exceptions.PathException( 'Expected decade range on form yyyy-yyyy') else: return first_year, last_year
def _get_directory(self, object_tree_folder, path): if len(path) == 0: return self._resolve_decades(object_tree_folder) elif len(path) == 1: decade_range_str = path[0] return self._resolve_years_in_decade(decade_range_str, object_tree_folder) else: try: year = int(path[1]) except ValueError: raise onedrive_exceptions.PathException( 'Expected year element in path') else: return self._resolve_objects_in_year(year, object_tree_folder)
def _resolve_taxa_classification_value(self, classification, value, object_tree_folder): d = directory.Directory() for pid in object_tree_folder.get_records['items']: record = self._object_tree.get_object_record(pid) try: if value in record[classification]: d.append(record['id']) except KeyError: pass # As empty folders in the taxa tree are pruned in the root and first level, # an empty folder here can only be due to an invalid path. if not len(d): raise onedrive_exceptions.PathException( 'Invalid taxonomic classification value') return d
def _get_region_tree_item_and_unconsumed_path( self, region_tree, path, parent_key='' ): """Return the region_tree item specified by path. An item can be a a folder (represented by a dictionary) or a PID (represented by None). This function is also used for determining which section of a path is within the region tree and which section should be passed to the next resolver. To support this, the logic is as follows: - If the path points to an item in the region tree, the item is returned and the path, having been fully consumed, is returned as an empty list. - If the path exits through a valid PID in the region tree, the PID is returned for the item and the section of the path that was not consumed within the region tree is returned. - If the path exits through a valid folder in the region tree, an "invalid path" PathException is raised. This is because only the PIDs are valid "exit points" in the tree. - If the path goes to an invalid location within the region tree, an "invalid path" PathException is raised. """ # Handle valid item within region tree. if not path: if region_tree is None: return parent_key, [] else: return region_tree, [] # Handle valid exit through PID. if region_tree is None: return parent_key, path # Handle next level in path. if path[0] in list(region_tree.keys()): return self._get_region_tree_item_and_unconsumed_path( region_tree[path[0]], path[1:], path[0] ) else: raise onedrive_exceptions.PathException('Invalid path')
def _raise_if_os_special_file(self, path): # For each file of "name", Finder on Mac OS X attempts to access ".name". if path[-1] in self._options.ignore_special: log.debug('Ignored file: {}'.format(path[-1])) raise onedrive_exceptions.PathException('Ignored OS special file')
def _resolver_lookup(self, path): try: return self._resolvers[path[0]] except KeyError: raise onedrive_exceptions.PathException('Invalid root directory')
def _raise_invalid_pid(self, pid): raise onedrive_exceptions.PathException('Invalid PID: {}'.format(pid))
def _raise_exception_if_empty_directory(self, directory, msg=None): """In hierarchies where ONEDrive dynamically renders directories only after having determined that there are contents for them, an empty directory means that the path is invalid.""" if len(directory) <= 2: raise onedrive_exceptions.PathException(msg)