FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
openai-python/src/openai/cli/_progress.py at main · doditz/openai-python · GitHub
doditz
/
openai-python
Public
forked from
openai/openai-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
openai-python
/
src
/
openai
/
cli
/
_progress.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
59 lines (41 loc) · 1.37 KB
Breadcrumbs
openai-python
/
src
/
openai
/
cli
/
_progress.py
Copy path
File metadata and controls
59 lines (41 loc) · 1.37 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from
__future__
import
annotations
import
io
from
typing
import
Callable
from
typing_extensions
import
override
class
CancelledError
(
Exception
):
def
__init__
(
self
,
msg
:
str
)
->
None
:
self
.
msg
=
msg
super
().
__init__
(
msg
)
@
override
def
__str__
(
self
)
->
str
:
return
self
.
msg
__repr__
=
__str__
class
BufferReader
(
io
.
BytesIO
):
def
__init__
(
self
,
buf
:
bytes
=
b""
,
desc
:
str
|
None
=
None
)
->
None
:
super
().
__init__
(
buf
)
self
.
_len
=
len
(
buf
)
self
.
_progress
=
0
self
.
_callback
=
progress
(
len
(
buf
),
desc
=
desc
)
def
__len__
(
self
)
->
int
:
return
self
.
_len
@
override
def
read
(
self
,
n
:
int
|
None
=
-
1
)
->
bytes
:
chunk
=
io
.
BytesIO
.
read
(
self
,
n
)
self
.
_progress
+=
len
(
chunk
)
try
:
self
.
_callback
(
self
.
_progress
)
except
Exception
as
e
:
# catches exception from the callback
raise
CancelledError
(
"The upload was cancelled: {}"
.
format
(
e
))
from
e
return
chunk
def
progress
(
total
:
float
,
desc
:
str
|
None
)
->
Callable
[[
float
],
None
]:
import
tqdm
meter
=
tqdm
.
tqdm
(
total
=
total
,
unit_scale
=
True
,
desc
=
desc
)
def
incr
(
progress
:
float
)
->
None
:
meter
.
n
=
progress
if
progress
==
total
:
meter
.
close
()
else
:
meter
.
refresh
()
return
incr
def
MB
(
i
:
int
)
->
int
:
return
int
(
i
//
1024
**
2
)
Back
|
FazBrowse Home
|
New Git URL