[ref] Move random_ascii to text utils

This commit is contained in:
Jérôme Lebleu 2015-07-13 17:44:00 +02:00
parent 10c3bee1e1
commit 927bba777f
2 changed files with 10 additions and 5 deletions

View file

@ -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

View file

@ -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')