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
596ab608
Commit
596ab608
authored
4 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
added encoding to read_lines and an unit test
parent
ff2d71be
No related branches found
Branches containing commit
Tags
v2.14.14
Tags containing commit
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
+4
-2
4 additions, 2 deletions
satella/files.py
tests/test_files.py
+9
-0
9 additions, 0 deletions
tests/test_files.py
with
16 additions
and
3 deletions
CHANGELOG.md
+
2
−
0
View file @
596ab608
# v2.14.33
*
added
`encoding`
to
`read_lines`
This diff is collapsed.
Click to expand it.
satella/__init__.py
+
1
−
1
View file @
596ab608
__version__
=
'
2.14.33a
1
'
__version__
=
'
2.14.33a
2
'
This diff is collapsed.
Click to expand it.
satella/files.py
+
4
−
2
View file @
596ab608
...
...
@@ -74,7 +74,8 @@ def _has_separator(path: str) -> bool:
return
any
(
map
(
lambda
x
:
x
in
path
,
SEPARATORS
))
def
read_lines
(
path
:
str
,
delete_empty_lines
:
bool
=
True
)
->
tp
.
List
[
str
]:
def
read_lines
(
path
:
str
,
delete_empty_lines
:
bool
=
True
,
encoding
:
str
=
'
utf-8
'
)
->
tp
.
List
[
str
]:
"""
Read lines from a particular file, removing end-of-line characters and optionally
empty lines. Additionally whitespaces (and end-of-line characters) will be removed
...
...
@@ -82,9 +83,10 @@ def read_lines(path: str, delete_empty_lines: bool = True) -> tp.List[str]:
:param path: path of file to read
:param delete_empty_lines: set to False if empty lines are not to be removed
:param encoding: encoding to read the file with
:return: each line as a separate entry
"""
with
open
(
path
,
'
r
'
)
as
f_in
:
with
codecs
.
open
(
path
,
'
r
'
,
encoding
)
as
f_in
:
lines
=
[
line
.
strip
()
for
line
in
f_in
.
readlines
()]
if
delete_empty_lines
:
lines
=
[
line
for
line
in
lines
if
line
]
...
...
This diff is collapsed.
Click to expand it.
tests/test_files.py
+
9
−
0
View file @
596ab608
...
...
@@ -20,6 +20,15 @@ class TestFiles(unittest.TestCase):
lines
=
read_lines
(
'
LICENSE
'
)
self
.
assertTrue
(
all
(
lines
))
with
open
(
'
test.tmp
'
,
'
w
'
)
as
f_out
:
f_out
.
write
(
'''
line1
line2
line3
'''
)
self
.
assertEqual
(
read_lines
(
'
test.tmp
'
),
[
'
line1
'
,
'
line2
'
,
'
line3
'
])
def
test_devnullfilelikeobject
(
self
):
null
=
DevNullFilelikeObject
()
self
.
assertEqual
(
null
.
write
(
'
ala
'
),
3
)
...
...
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