Improvement for an --eval mechanism

This commit is contained in:
Miroslav Stampar 2013-08-31 00:28:51 +02:00
parent 3a57af1452
commit dd39913cf6

View File

@ -774,17 +774,30 @@ class Connect(object):
for name, value in variables.items(): for name, value in variables.items():
if name != "__builtins__" and originals.get(name, "") != value: if name != "__builtins__" and originals.get(name, "") != value:
if isinstance(value, (basestring, int)): if isinstance(value, (basestring, int)):
found = False
value = unicode(value) value = unicode(value)
if re.search(r"\b%s=" % name, (get or "")):
get = re.sub("((\A|\W)%s=)([^%s]+)" % (name, delimiter), "\g<1>%s" % value, get) regex = r"((\A|%s)%s=).+?(%s|\Z)" % (re.escape(delimiter), name, re.escape(delimiter))
elif re.search(r"\b%s=" % name, (post or "")): if re.search(regex, (get or "")):
post = re.sub("((\A|\W)%s=)([^%s]+)" % (name, delimiter), "\g<1>%s" % value, post) found = True
elif re.search(r"\b%s=" % name, (cookie or "")): get = re.sub(regex, "\g<1>%s\g<3>" % value, get)
cookie = re.sub("((\A|\W)%s=)([^%s]+)" % (name, conf.cDel or DEFAULT_COOKIE_DELIMITER), "\g<1>%s" % value, cookie)
elif post is not None: if re.search(regex, (post or "")):
post += "%s%s=%s" % (delimiter, name, value) found = True
elif get is not None: post = re.sub(regex, "\g<1>%s\g<3>" % value, post)
get += "%s%s=%s" % (delimiter, name, value)
regex = r"((\A|%s)%s=).+?(%s|\Z)" % (re.escape(conf.cDel or DEFAULT_COOKIE_DELIMITER), name, re.escape(conf.cDel or DEFAULT_COOKIE_DELIMITER))
if re.search(regex, (cookie or "")):
found = True
cookie = re.sub(regex, "\g<1>%s\g<3>" % value, cookie)
if not found:
if post is not None:
post += "%s%s=%s" % (delimiter, name, value)
elif get is not None:
get += "%s%s=%s" % (delimiter, name, value)
elif cookie is not None:
cookie += "%s%s=%s" % (conf.cDel or DEFAULT_COOKIE_DELIMITER, name, value)
if not conf.skipUrlEncode: if not conf.skipUrlEncode:
get = urlencode(get, limit=True) get = urlencode(get, limit=True)