From e4ddb8b55ed2a881d9d692e9c6d2b7416dcdec96 Mon Sep 17 00:00:00 2001 From: Sebastian Wehling Date: Fri, 25 Jul 2014 14:14:19 +0200 Subject: [PATCH] new module utils within package util containing helpers for this and that --- pylot/core/util/utils.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 pylot/core/util/utils.py diff --git a/pylot/core/util/utils.py b/pylot/core/util/utils.py new file mode 100644 index 00000000..fd1fa215 --- /dev/null +++ b/pylot/core/util/utils.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python +# +# -*- coding: utf-8 -*- + +import re + +def fnConstructor(s): + + badchars = re.compile(r'[^A-Za-z0-9_. ]+|^\.|\.$|^ | $|^$') + badsuffix = re.compile(r'(aux|com[1-9]|con|lpt[1-9]|prn)(\.|$)') + + fn = badchars.sub('_', s) + + if badsuffix.match(fn): + fn = '_' + fn + return fn