Oops -- I missed the subject line on my last post. On 10 Aug 2006, at 9:41 AM, [EMAIL PROTECTED] wrote:
While I appreciate the suggestion, this is exactly the route I don't want to take -- it essentially involves rewriting the Python parser/tokenizer, which has already been written and tested by people much more qualified than I. In fact, the code I was using (Frederik's code) has already been written and tested by people much more qualified than I, and it _still_ doesn't work. A shortcut occurs to me; maybe someone can tell me what's wrong with my reasoning here. It seems that any string that is unsafe to pass to eval() must involve a function call, and thus must contain an opening paren. Given that I know that the data I expect contains no parens, would people expect this code to be safe: START_MARKER = 'var table_body = ' END_MARKER = '];' def extractStockData(data): pos1 = data.find(START_MARKER) pos2 = data.find(END_MARKER, pos1) parenPos = data.find('(') if parenPos >= 0: raise "Data format changed -- found a paren" else: return eval(data[pos1+len(START_MARKER):pos2+1]) B. -- Brendon Towle, PhD Cognitive Scientist +1-412-690-2442x127 Carnegie Learning, Inc. The Cognitive Tutor Company ® Helping over 375,000 students in 1000 school districts succeed in math. |
-- http://mail.python.org/mailman/listinfo/python-list