Добавлена локальная функция rnd() для профилей

git-svn-id: http://svn.calculate.ru/calculate2/calculate-lib/trunk@789 c91db197-33c1-4113-bf15-f8a5c547ca64
develop
asamoukin 15 years ago
parent c7c5c0bd7c
commit 2c5529a019

@ -24,6 +24,8 @@ from xml import xpath
import popen2
import types
import copy
import random
import string
tr = cl_base.lang()
tr.setLocalDomain('cl_lib')
@ -2317,6 +2319,49 @@ class profile(_file, _terms):
textProfileTmp[resS.end():]
return textProfileTmp
def funcRnd(funTxt,resS,textProfileTmp):
"""локальная функция выдает строку случайных символов
первый аргумент:
'num' - числа,
'pas' - цифры и буквы
второй аргумент:
количество символов
"""
terms = funTxt[4:-1].replace(" ","").split(",")
if not terms[0].strip() or\
(len(terms)==2 and not terms[1].strip()) or\
len(terms)!=2:
print _("error in profile %s")%nameProfile
print _("error profile term %s")%str(funTxt)
exit(1)
fArgvNames = ['num','pas']
if not terms[0] in fArgvNames:
print _("error in profile %s")%nameProfile
print _("error profile term %s")%str(funTxt)
print _("first argument function is not 'num' or 'pas'")
exit(1)
try:
lenStr = int(terms[1])
except:
print _("error in profile %s")%nameProfile
print _("error profile term %s")%str(funTxt)
print _("two argument function is not number")
exit(1)
if terms[0] == fArgvNames[0]:
replace=''.join([random.choice(string.digits)\
for i in xrange(lenStr)])
elif terms[0] == fArgvNames[1]:
replace=''.join([random.choice(string.ascii_letters + \
string.digits) for i in xrange(lenStr)])
else:
print _("error in profile %s")%nameProfile
print _("error profile term %s")%str(funTxt)
exit(1)
textProfileTmp = textProfileTmp[:resS.start()] + replace +\
textProfileTmp[resS.end():]
return textProfileTmp
# Локальные переменные
localVars = {}
# Локальные переменные для функции load
@ -2341,6 +2386,9 @@ class profile(_file, _terms):
elif funTxt[:4] == "pkg(":
textProfileTmp = funcPkg(funTxt,resS,textProfileTmp)
resS = self._reFunc.search(textProfileTmp)
elif funTxt[:4] == "rnd(":
textProfileTmp = funcRnd(funTxt,resS,textProfileTmp)
resS = self._reFunc.search(textProfileTmp)
else:
resS = False
return textProfileTmp

Loading…
Cancel
Save