Nice Tim! thanks Alot for taking time at analyzing C source code of Python!
So here it checks for preventing overflows, I C . Good work, We are glad to have you on the Web2py group Tim. Regards, Phyo. Star-Nix Solutions On Fri, Oct 17, 2008 at 3:17 PM, Timothy Farrell <[EMAIL PROTECTED]> wrote: > I see. > > Looking at the *replace_interleave *function at > http://svn.python.org/view/python/branches/release25-maint/Objects/stringobject.c?rev=66121&view=auto, > you can see where it checks for an overflow error (about 20 lines down). > It appears to be an architectural limitation based on the implementation > rather than one imposed by the interpreter. > > The code in question: > > */* Check for overflow */* > */* result_len = count * to_len + self_len; */* > product = count * to_len; > *if* (product / to_len != count) { > PyErr_SetString(PyExc_OverflowError, > *"replace string is too long"*); > *return* NULL; > } > result_len = product + self_len; > *if* (result_len < 0) { > PyErr_SetString(PyExc_OverflowError, > *"replace string is too long"*); > *return* NULL; > } > > It may be the case that 502, is not so much a problem as your source string > may be too long, since this seems to calculate the max based on a > combination of the two. > > Disclaimer: For anyone reading this who is unfamiliar with C and seeing the > above code, it is C-code not Python-code, just so you wouldn't be confused. > > -tim > > > Phyo Arkar wrote: > > Dear Tim; > > Thanks for quick response all the time. > > I am thinking about using re , but i would like to know and confirm if > str.replace() have limitations on size of string. Which dosen't seem to be > documented.. > > Regards, > > Phyo. > > On Fri, Oct 17, 2008 at 3:02 PM, Timothy Farrell <[EMAIL PROTECTED]>wrote: > >> Regular Expressions would probably be more robust...but doing such a >> large replace seems odd to me. If it were my code I would look for a >> way around not having so much that needed replacing. Or perhaps you >> should use string slicing. Anyway, here's how you would do it with >> regexps: >> >> import re >> re.subn(r'.{1-502}' ,'replacewiththis', srcString) >> >> Phyo Arkar wrote: >> > Dear All; >> > >> > If anyone knows ?I would like to know if there Size Limitation on >> > str.replace() function. >> > >> > Because from what i have tested , it no-longer replace anything after >> > 502 length of string. >> > >> > I want to replace a huge block of string and that , i am having >> problem. >> > >> > Regards, >> > >> > Phyo. >> > >> > >> > >> > >> > >> > > >> >> >> > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---

