mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[enh] Add prependlines method to text formatting utils
This commit is contained in:
parent
df5cd5ad7f
commit
f8f8bfca79
1 changed files with 9 additions and 1 deletions
|
@ -2,7 +2,7 @@ import re
|
||||||
import mmap
|
import mmap
|
||||||
|
|
||||||
|
|
||||||
# Searching helpers ----------------------------------------------------
|
# Pattern searching ----------------------------------------------------
|
||||||
|
|
||||||
def search(pattern, text, count=0, flags=0):
|
def search(pattern, text, count=0, flags=0):
|
||||||
"""Search for pattern in a text
|
"""Search for pattern in a text
|
||||||
|
@ -48,3 +48,11 @@ def searchf(pattern, path, count=0, flags=re.MULTILINE):
|
||||||
match = search(pattern, data, count, flags)
|
match = search(pattern, data, count, flags)
|
||||||
data.close()
|
data.close()
|
||||||
return match
|
return match
|
||||||
|
|
||||||
|
|
||||||
|
# Text formatting ------------------------------------------------------
|
||||||
|
|
||||||
|
def prependlines(text, prepend):
|
||||||
|
"""Prepend a string to each line of a text"""
|
||||||
|
lines = text.splitlines(True)
|
||||||
|
return "%s%s" % (prepend, prepend.join(lines))
|
||||||
|
|
Loading…
Reference in a new issue