Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
1e2687e7
Commit
1e2687e7
authored
1 year ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
* added AutoflushFile.seek()
* added AutoflushFile.truncate()
parent
34797dce
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGELOG.md
+2
-0
2 additions, 0 deletions
CHANGELOG.md
satella/__init__.py
+1
-1
1 addition, 1 deletion
satella/__init__.py
satella/files.py
+22
-1
22 additions, 1 deletion
satella/files.py
tests/test_files.py
+2
-0
2 additions, 0 deletions
tests/test_files.py
with
27 additions
and
2 deletions
CHANGELOG.md
+
2
−
0
View file @
1e2687e7
# v2.23.5
*
added AutoflushFile.seek()
*
added AutoflushFile.truncate()
This diff is collapsed.
Click to expand it.
satella/__init__.py
+
1
−
1
View file @
1e2687e7
__version__
=
'
2.23.5a
1
'
__version__
=
'
2.23.5a
2
'
This diff is collapsed.
Click to expand it.
satella/files.py
+
22
−
1
View file @
1e2687e7
...
...
@@ -378,6 +378,13 @@ class AutoflushFile(Proxy[io.FileIO]):
super
().
__init__
(
fle
)
self
.
__dict__
[
'
pointer
'
]
=
fle
.
tell
()
def
seek
(
self
,
*
args
,
**
kwargs
)
->
int
:
"""
Seek to a provided position within the file
"""
fle
=
self
.
_open_file
()
v
=
fle
.
seek
(
*
args
,
**
kwargs
)
self
.
__dict__
[
'
pointer
'
]
=
fle
.
tell
()
return
v
def
read
(
self
,
*
args
,
**
kwargs
)
->
tp
.
Union
[
str
,
bytes
]:
"""
Read a file, returning the read-in data
...
...
@@ -393,7 +400,12 @@ class AutoflushFile(Proxy[io.FileIO]):
def
_get_file
(
self
)
->
tp
.
Optional
[
AutoflushFile
]:
return
self
.
__dict__
.
get
(
'
_Proxy__obj
'
)
def
_open_file
(
self
)
->
open
:
def
readall
(
self
)
->
tp
.
Union
[
str
,
bytes
]:
"""
Read all contents into the file
"""
file
=
self
.
_open_file
()
return
file
.
readall
()
def
_open_file
(
self
)
->
io
.
FileIO
:
file
=
self
.
_get_file
()
if
file
is
None
:
file
=
open
(
*
self
.
con_args
,
**
self
.
con_kwargs
)
...
...
@@ -428,3 +440,12 @@ class AutoflushFile(Proxy[io.FileIO]):
self
.
__dict__
[
'
pointer
'
]
=
file
.
tell
()
self
.
_close_file
()
return
val
def
truncate
(
self
,
__size
:
tp
.
Optional
[
int
]
=
None
)
->
int
:
"""
Truncate file to __size starting bytes
"""
fle
=
self
.
_open_file
()
v
=
fle
.
truncate
(
__size
)
self
.
__dict__
[
'
pointer
'
]
=
fle
.
tell
()
self
.
_close_file
()
return
v
This diff is collapsed.
Click to expand it.
tests/test_files.py
+
2
−
0
View file @
1e2687e7
...
...
@@ -26,6 +26,8 @@ class TestFiles(unittest.TestCase):
assert
read_in_file
(
'
test3.txt
'
,
encoding
=
'
utf-8
'
)
==
'
test
'
af
.
write
(
'
test2
'
)
assert
read_in_file
(
'
test3.txt
'
,
encoding
=
'
utf-8
'
)
==
'
testtest2
'
af
.
truncate
(
4
)
assert
read_in_file
(
'
test3.txt
'
,
encoding
=
'
utf-8
'
)
==
'
test
'
finally
:
af
.
close
()
try_unlink
(
'
test3.txt
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment