Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
fix fileio coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
ifndef012 committed Jul 18, 2020
1 parent 5d6dfc0 commit 573a4e8
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions submarine-sdk/pysubmarine/submarine/utils/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

import io
from urllib.parse import urlparse
from pathlib import Path
from pathlib import Path
from typing import Tuple


def open_buffered_file_reader(
uri: str,
buffer_size: int = io.DEFAULT_BUFFER_SIZE) -> io.BufferedReader:
Expand All @@ -31,6 +32,7 @@ def open_buffered_file_reader(
input_file.close()
raise e


def open_buffered_stream_writer(
uri: str,
buffer_size: int = io.DEFAULT_BUFFER_SIZE) -> io.BufferedWriter:
Expand All @@ -41,33 +43,34 @@ def open_buffered_stream_writer(
output_stream.close()
raise e


def write_file(buffer: io.BytesIO,
uri: str,
buffer_size: int = io.DEFAULT_BUFFER_SIZE) -> None:
with open_buffered_stream_writer(uri, buffer_size=buffer_size) as output_stream:
with open_buffered_stream_writer(uri,
buffer_size=buffer_size) as output_stream:
output_stream.write(buffer.getbuffer())


def open_input_file(uri: str) -> NativeFile:
filesystem, path = _parse_uri(uri)
return filesystem.open_input_file(path)


def open_output_stream(uri: str) -> NativeFile:
filesystem, path = _parse_uri(uri)
return filesystem.open_output_stream(path)


def file_info(uri: str) -> fs.FileInfo:
filesystem, path = _parse_uri(uri)
info, = filesystem.get_file_info([path])
return info

def _parse_uri(uri: str) -> Tuple[fs.FileSystem, str]:
parsed = urlparse(uri)
uri = uri if parsed.scheme else str(Path(parsed.path).expanduser().resolve())
filesystem, path = fs.FileSystem.from_uri(uri)
return filesystem, path






def _parse_uri(uri: str) -> Tuple[fs.FileSystem, str]:
parsed = urlparse(uri)
uri = uri if parsed.scheme else str(
Path(parsed.path).expanduser().resolve())
filesystem, path = fs.FileSystem.from_uri(uri)
return filesystem, path

0 comments on commit 573a4e8

Please sign in to comment.