From 84c2f0eff1070c8fa822e8937773050e9706615d Mon Sep 17 00:00:00 2001 From: gdetrez Date: Wed, 25 Oct 2006 21:08:01 +0200 Subject: [PATCH] fonction pour transformer une chaine en argument pour un shell darcs-hash:20061025190801-f46e9-6c9b9b18b8be02f4829aa3f2ff225104c395e75c.gz --- lib/utils/__init__.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/utils/__init__.py b/lib/utils/__init__.py index e69de29b..c50c88ce 100644 --- a/lib/utils/__init__.py +++ b/lib/utils/__init__.py @@ -0,0 +1,24 @@ +import re + +def __init__(): + pass + +def QuoteForPOSIX(string): + '''quote a string so it can be used as an argument in a posix shell + + According to: http://www.unix.org/single_unix_specification/ + 2.2.1 Escape Character (Backslash) + + A backslash that is not quoted shall preserve the literal value + of the following character, with the exception of a . + + 2.2.2 Single-Quotes + + Enclosing characters in single-quotes ( '' ) shall preserve + the literal value of each character within the single-quotes. + A single-quote cannot occur within single-quotes. + + source : http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498202 + ''' + + return "\\'".join(["'" + p + "'" for p in string.split("'")])