mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[ref] Move random_ascii to text utils
This commit is contained in:
parent
10c3bee1e1
commit
927bba777f
2 changed files with 10 additions and 5 deletions
|
@ -4,7 +4,6 @@ import os
|
|||
import re
|
||||
import errno
|
||||
import logging
|
||||
import binascii
|
||||
import argparse
|
||||
from json import dumps as json_encode
|
||||
|
||||
|
@ -19,16 +18,13 @@ from moulinette.interfaces import (
|
|||
BaseActionsMapParser, BaseInterface, ExtendedArgumentParser,
|
||||
)
|
||||
from moulinette.utils.serialize import JSONExtendedEncoder
|
||||
from moulinette.utils.text import random_ascii
|
||||
|
||||
logger = logging.getLogger('moulinette.interface.api')
|
||||
|
||||
|
||||
# API helpers ----------------------------------------------------------
|
||||
|
||||
def random_ascii(length=20):
|
||||
"""Return a random ascii string"""
|
||||
return binascii.hexlify(os.urandom(length)).decode('ascii')
|
||||
|
||||
class _HTTPArgumentParser(object):
|
||||
"""Argument parser for HTTP requests
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import os
|
||||
import re
|
||||
import mmap
|
||||
import binascii
|
||||
|
||||
|
||||
# Pattern searching ----------------------------------------------------
|
||||
|
@ -56,3 +58,10 @@ def prependlines(text, prepend):
|
|||
"""Prepend a string to each line of a text"""
|
||||
lines = text.splitlines(True)
|
||||
return "%s%s" % (prepend, prepend.join(lines))
|
||||
|
||||
|
||||
# Randomize ------------------------------------------------------------
|
||||
|
||||
def random_ascii(length=20):
|
||||
"""Return a random ascii string"""
|
||||
return binascii.hexlify(os.urandom(length)).decode('ascii')
|
||||
|
|
Loading…
Reference in a new issue