Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions linuxpy/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@
# Copyright (c) 2023 Tiago Coutinho
# Distributed under the GPLv3 license. See LICENSE for more info.

import typing
import functools
import importlib
import os
import io
import select

StrOrBytesPath: typing.TypeAlias = str | bytes | os.PathLike[str] | os.PathLike[bytes]

def fopen(path, rw=False, binary=True, blocking=False, close_on_exec=True):
FileDescriptorOrPath: typing.TypeAlias = int | StrOrBytesPath


def fopen(
path: StrOrBytesPath,
rw: bool = False,
binary: bool = True,
blocking: bool = False,
close_on_exec: bool = True
) -> io.FileIO | io.TextIOWrapper:
def opener(path, flags):
if not blocking:
flags |= os.O_NONBLOCK
Expand Down Expand Up @@ -39,7 +51,7 @@ class IO:


class GeventModule:
def __init__(self, name):
def __init__(self, name: str):
self.name = name
self._module = None

Expand All @@ -49,15 +61,15 @@ def module(self):
self._module = importlib.import_module(f"gevent.{self.name}")
return self._module

def __getattr__(self, name):
def __getattr__(self, name: str):
attr = getattr(self.module, name)
setattr(self, name, attr)
return attr


class GeventIO:
@staticmethod
def open(path, rw=False, blocking=False):
def open(path: FileDescriptorOrPath, rw: bool = False, blocking: bool = False):
mode = "rb+" if rw else "rb"
import gevent.fileobject

Expand Down
Loading