Re: Regex Validators doesn't validate while working in a shell
On Monday, 12 September 2016 14:36:23 UTC+1, ashish...@finoit.co.in wrote: > > I've configured user's username field in following way > > username = models.CharField( > _('username'), > max_length=30, > unique=True, > help_text=_('Required. 30 characters or fewer. Letters, digits > and @/./+/-/_ only.'), > validators=[ > validators.RegexValidator( > r'^[\w.+-]+$', > _('Enter a valid username. This value may contain only ' > 'letters, numbers ' 'and ./+/-/_ characters.') > ), > ], > error_messages={ > 'unique': _("A user with that username already exists."), > }, > ) > > I'm getting error in admin panel but not in django-shell. > > > Though django raises an error for maximum length in shell. > > Is it a bug? Or am I missing something. > This has nothing to do with being in the shell. Validators aren't run on save, and that is the case everywhere, as noted explicitly in the validators documentation: https://docs.djangoproject.com/en/1.10/ref/validators/#how-validators-are-run -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9fa63938-11d8-40ca-b3b5-d531aa295c9c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: regex error?
try this one url(r'/(?P\d+)$', DetailView.as_view( model = Customer, template_name="customer.html")), Many thanks, Serge +380 636150445 skype: skhohlov -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CADTRxJMX0sF6AUbtbtOAzaJcdjJ6WJGgL_RvoxdJnrufMKn3MA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: regex error?
ive also tried url(r'^customers/([0-9])/$', DetailView.as_view( model = Customer, template_name="customer.html")), -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/623792ae-7ecd-4177-b2e1-ec502781c157%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
RE: regex
'.' matches any character except a new line Sent from my Windows Phone -- From: arm Sent: 1/25/2013 10:09 AM To: django-users@googlegroups.com Subject: regex Hi, I'm trying to figure out the regular expressions that will match any number and punctuation and chars like +,#,§ etc . Any advice? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: regex
On Fri, Jan 25, 2013 at 2:09 AM, arm wrote: > > Hi, > > I'm trying to figure out the regular expressions that will match any > number and punctuation and chars like +,#,§ etc . Any advice? http://www.regular-expressions.info/charclass.html -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: Regex problem in urls
Based on the urls.py file you are showing us, it seems like /start/ should be a valid url. Are you running the dev server with automatic reloading? Sometimes you need to force a reload on it to see changes. (I normally notice that in the admin, but it could come up anywhere stuff gets cached in memory for performance on startup). Alex On Jul 29, 4:18 pm, Gordy wrote: > I'm a rookie at Django so this is probably something obvious. > > My urls.py looks like this: > > from django.conf.urls.defaults import * > > # Uncomment the next two lines to enable the admin: > from django.contrib import admin > admin.autodiscover() > > urlpatterns = patterns('', > # Example: > # (r'^sunlight/', include('sunlight.foo.urls')), > > # Uncomment the admin/doc line below and add > 'django.contrib.admindocs' > # to INSTALLED_APPS to enable admin documentation: > (r'^admin/doc/', include('django.contrib.admindocs.urls')), > > # Uncomment the next line to enable the admin: > (r'^admin/(.*)', 'admin.site.root'), > (r'^start/', 'sunlight.start.views.index'), > (r'req/','sunlight.requests.views.index'), > ) > ~ > > When I hit the site, I get: > > Page not found (404) > Request Method: GET > Request URL: http://server2/start/ > > Using the URLconf defined in sunlight.urls, Django tried these URL > patterns, in this order: > > 1. ^admin/doc/ > 2. ^admin/(.*) > 3. ^[/]$ > 4. req/ > > The current URL, start/, didn't match any of these. > > So it looks like it isn't properly interpreting the regex on line 3. > > Any help would be appreciated. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: regex infinite loop with 100% cpu use in django.forms.fields.email_re - DOS hole?
On Fri, 2009-10-09 at 12:21 -0700, davisd wrote: > Sorry for the public disclosure... I did email django security after > I posted. I'm just getting into this open source goodness and I'm not > really sure how it's supposed to operate yet. > > I did consult the documentation: > http://docs.djangoproject.com/en/dev/internals/contributing/ > > Jacob: > I'm running django from SVN > Python 2.6.2 > I believe the Operating system is moot- it's all in the python. > Linux kernel 2.6.31-11, but also 2.6.18.8 - > > I'm wondering if a multithreaded webserver setup would be more guarded > against this sort of thing? > This bug has no effect on FreeBSD systems I've tested, so it looks like it is OS specific. FreeBSD 7.0, 7.1, 7.2 + python 2.5.4 work fine. > $ time python -c "from django.forms.fields import email_re; > email_re.match('viewx3dtextx26q...@yahoo.comx26latlngx3d15854521645943074058'); > import django; print django.VERSION" (1, 1, 0, 'final', 0) real0m0.086s user0m0.055s sys 0m0.029s Linux 2.6.27 + python 2.5.4 fails. > $ time python -c "from django.forms.fields import email_re; > email_re.match('viewx3dtextx26q...@yahoo.comx26latlngx3d15854521645943074058'); > import django; print django.VERSION" ^CTraceback (most recent call last): File "", line 1, in KeyboardInterrupt real0m21.317s user0m21.173s sys 0m0.044s Cheers Tom --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex infinite loop with 100% cpu use in django.forms.fields.email_re - DOS hole?
Just as an update for anyone following this thread: This was indeed a security exploit, and it has been fixed. See http://www.djangoproject.com/weblog/2009/oct/09/security/ for details. Jacob --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex infinite loop with 100% cpu use in django.forms.fields.email_re - DOS hole?
On Fri, Oct 9, 2009 at 3:21 PM, davisd wrote: > > I'm wondering if a multithreaded webserver setup would be more guarded > against this sort of thing? > > Yeah, but. When I tried this on my own production server (Apache/mod_wsgi) the process handling the request that caused the problem was killed after the deadlock timeout was reached. But deadlock timeout can't really protect you from a determined denial of service attack, so it's still a problem in Django. Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex infinite loop with 100% cpu use in django.forms.fields.email_re - DOS hole?
Sorry for the public disclosure... I did email django security after I posted. I'm just getting into this open source goodness and I'm not really sure how it's supposed to operate yet. I did consult the documentation: http://docs.djangoproject.com/en/dev/internals/contributing/ Jacob: I'm running django from SVN Python 2.6.2 I believe the Operating system is moot- it's all in the python. Linux kernel 2.6.31-11, but also 2.6.18.8 - I'm wondering if a multithreaded webserver setup would be more guarded against this sort of thing? On Oct 9, 2:18 pm, James Bennett wrote: > Yes. > > We've confirmed the problem. We're working on a patch. > > In the meantime, everybody go meditate on the documentation for how to > report security issues. > > -- > "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex infinite loop with 100% cpu use in django.forms.fields.email_re - DOS hole?
Yes. We've confirmed the problem. We're working on a patch. In the meantime, everybody go meditate on the documentation for how to report security issues. -- "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex infinite loop with 100% cpu use in django.forms.fields.email_re - DOS hole?
Take a look at mine: *In [41]: from django.forms.fields django.forms.fields In [41]: from django.forms.fields import email_re In [42]: email_re.match('viewx3dtextx26q...@yahoo.comx26latlngx3d15854521645943074058 ')* and this is what top shows: * PID USER PR NI VIRT RES SHR S %CPU %MEMTIME+ COMMAND 13886 juan 20 0 17556 12m 1992 R 95 1.3 0:59.61 ipyth*on and stays like that for ever... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex infinite loop with 100% cpu use in django.forms.fields.email_re - DOS hole?
Ok! I just confirmed this, I took down a live server! (On of my own) All I had to do was put the email address in the contact form. -David On Oct 9, 1:13 pm, davisd wrote: > After hours of debugging, I found that: > > from django.forms.fields import email_re > email_re.match > ('viewx3dtextx26q...@yahoo.comx26latlngx3d15854521645943074058') > > will cause CPU to shoot up 100% and the process will hang forever. > > Since this is the regex used to validate EmailField on forms, won't > this DOS a live site? > > Where should I report this? > > Is there a better way to validate an email address? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex query delivering incorrect results
Hi Karen, On 28 Sep., 22:49, Karen Tracey wrote: > On Mon, Sep 28, 2009 at 4:00 PM, janedenone wrote: > > > Hi, > > > this > > > pages = Page.objects.exclude(content__iregex=r'^[\n\r \t]*<') > > > should deliver the same rows as this > > > SELECT ... FROM pages WHERE (content NOT REGEXP '^[\n\r \t]*<') > > > but it does not: The Django query delivers 468 rows, whereas the SQL > > query delivers 223. It could be that the Django query does not > > recognize line endings as mentioned in the character class. Am I > > missing something? > > The Django query is going to be an SQL query also. To see what Django is > sending to the DB you should recreate in a shell session and then: > > >>> from django.db import connection > >>> connection.queries[-1] > > to see how the query you are expecting compares to the query that is > actually being issued. (Note the sql in connection.queries won't have the > necessary quotes around the regexp parameter -- this quoting is done by the > backend and therefore not logged in the version stored in > connection.queries). > Thanks a lot! I am aware that Django creates SQL queries for me, but I did not know how to make them visible. connection.queries shows that the backslashes preceding my special characters had been escaped: u'SELECT ... WHERE (NOT (`pages`.`content` REGEXP ^[\\n\\r \\t]*< ) AND NOT (`pages`.`content` REGEXP ^[\\n\\r \\t]*$ ) and I fixed this by changing the Django expression from pages = Page.objects.exclude(content__iregex=r'^[\n\r \t]*<').exclude (content__iregex=r'^[\n\r \t]*$') to pages = Page.objects.exclude(content__iregex=u'^[\n\r \t]*<').exclude (content__iregex=u'^[\n\r \t]*$') Thanks again, Jan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex query delivering incorrect results
On Mon, Sep 28, 2009 at 4:00 PM, janedenone wrote: > > Hi, > > this > > pages = Page.objects.exclude(content__iregex=r'^[\n\r \t]*<') > > should deliver the same rows as this > > SELECT ... FROM pages WHERE (content NOT REGEXP '^[\n\r \t]*<') > > but it does not: The Django query delivers 468 rows, whereas the SQL > query delivers 223. It could be that the Django query does not > recognize line endings as mentioned in the character class. Am I > missing something? > > The Django query is going to be an SQL query also. To see what Django is sending to the DB you should recreate in a shell session and then: >>> from django.db import connection >>> connection.queries[-1] to see how the query you are expecting compares to the query that is actually being issued. (Note the sql in connection.queries won't have the necessary quotes around the regexp parameter -- this quoting is done by the backend and therefore not logged in the version stored in connection.queries). Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex problem in urls.py in Django 1.1/mod_wsgi
My noob error: I had extra "portal/" on my regex. Sorry and thanks for your attention. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex problem in urls.py in Django 1.1/mod_wsgi
On Sep 6, 3:52 pm, Karen Tracey wrote: > On Sun, Sep 6, 2009 at 1:36 AM, Jim Myers wrote: > > > Thanks, but that doesn't do it either. > > I changed the regex to: > > > ^portal/student/(?P\S+)/profile_edit/$ > > > and it still doesn't match :( > > It should: > > >>> import re > >>> re.match(r'^portal/student/(?P\S+)/profile_edit/$', > > 'portal/student/xx.yy/profile_edit/').groupdict() > {'userid': 'xx.yy'} > > > > I don't know what to tell you. The regex now matches the url you specified. > url mapping isn't fundamentally broken in Django. There's got to be > something else going on in your scenario... There is always the failing to restart Apache after changes option. ;-) Graham > Karen > > On Sep 5, 9:44 pm, Karen Tracey wrote: > > > > > > On Sat, Sep 5, 2009 at 11:32 PM, Jim Myers wrote: > > > > > Hi, I'm using this regex in urls.py: > > > > > r'^portal/student/(?P\S+)/profile_edit$' > > > > > There's no trailing slash on this regex, but there is an end of string > > > > marker ($). So a match will have to end with 'profile_edit', no trailing > > > slash. > > > > > to try to match this url: > > > > >http://dd..org/portal/student/xx.yy/profile_edit/ > > > > This url ends with a trailing slash, thus won't match the above regex. > > > > Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex problem in urls.py in Django 1.1/mod_wsgi
On Sun, Sep 6, 2009 at 1:36 AM, Jim Myers wrote: > > Thanks, but that doesn't do it either. > I changed the regex to: > > ^portal/student/(?P\S+)/profile_edit/$ > > and it still doesn't match :( > > It should: >>> import re >>> re.match(r'^portal/student/(?P\S+)/profile_edit/$', 'portal/student/xx.yy/profile_edit/').groupdict() {'userid': 'xx.yy'} >>> I don't know what to tell you. The regex now matches the url you specified. url mapping isn't fundamentally broken in Django. There's got to be something else going on in your scenario... Karen On Sep 5, 9:44 pm, Karen Tracey wrote: > > On Sat, Sep 5, 2009 at 11:32 PM, Jim Myers wrote: > > > > > Hi, I'm using this regex in urls.py: > > > > > r'^portal/student/(?P\S+)/profile_edit$' > > > > > There's no trailing slash on this regex, but there is an end of string > > > > marker ($). So a match will have to end with 'profile_edit', no trailing > > slash. > > > > > to try to match this url: > > > > >http://dd..org/portal/student/xx.yy/profile_edit/ > > > > This url ends with a trailing slash, thus won't match the above regex. > > > > Karen > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex problem in urls.py in Django 1.1/mod_wsgi
Thanks, but that doesn't do it either. I changed the regex to: ^portal/student/(?P\S+)/profile_edit/$ and it still doesn't match :( On Sep 5, 9:44 pm, Karen Tracey wrote: > On Sat, Sep 5, 2009 at 11:32 PM, Jim Myers wrote: > > > Hi, I'm using this regex in urls.py: > > > r'^portal/student/(?P\S+)/profile_edit$' > > > There's no trailing slash on this regex, but there is an end of string > > marker ($). So a match will have to end with 'profile_edit', no trailing > slash. > > > to try to match this url: > > >http://dd..org/portal/student/xx.yy/profile_edit/ > > This url ends with a trailing slash, thus won't match the above regex. > > Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex problem in urls.py in Django 1.1/mod_wsgi
On Sat, Sep 5, 2009 at 11:32 PM, Jim Myers wrote: > > Hi, I'm using this regex in urls.py: > > r'^portal/student/(?P\S+)/profile_edit$' > > There's no trailing slash on this regex, but there is an end of string marker ($). So a match will have to end with 'profile_edit', no trailing slash. > to try to match this url: > > http://dd..org/portal/student/xx.yy/profile_edit/ > > This url ends with a trailing slash, thus won't match the above regex. Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex problem in django
On Jun 29, 2:57 pm, Joru wrote: > Still doesn't work even I remove wrap function :( So it seems your regex is incorrect, the problem is not related to Django. If you paste your code here I can have a look, but I still think you'd be better off reading a bit more about regular expressions yourself. The last link I posted wasn't very useful for learning because it is just a reference, there is a proper tutorial on regular expressions with Python here: http://www.amk.ca/python/howto/regex/ James --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex problem in django
Still doesn't work even I remove wrap function :( On Jun 29, 7:35 pm, James Gregory wrote: > On Jun 29, 1:05 pm, Joru wrote: > > > I'm sorry for my typo > > the string var suppose to be like this > > str = "wr:\n one bunny \n two bunny \n wr:\n three bunny \n > > So every match string "wr:" should had "+" in front of it line > > the one that confuse me is that my function work in django/python > > shell, but thisregexdoesn't work well if i called it from views.py > > of my django app > > So the problem that I faced is that, how come when using django/python > > shell. myregexwork but not if I put in on my views.py > > Any hint? > > I may be wrong, but I suspect there is a difference between the input > string/code you are using in the shell, and the input string/code you > are using in the view. What happens if make a new empty Python script > and cut and paste in your code (removing the wrap function from > Django). Does it work then? > > James --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex problem in django
On Jun 29, 1:05 pm, Joru wrote: > I'm sorry for my typo > the string var suppose to be like this > str = "wr:\n one bunny \n two bunny \n wr:\n three bunny \n > So every match string "wr:" should had "+" in front of it line > the one that confuse me is that my function work in django/python > shell, but this regex doesn't work well if i called it from views.py > of my django app > So the problem that I faced is that, how come when using django/python > shell. my regex work but not if I put in on my views.py > Any hint? I may be wrong, but I suspect there is a difference between the input string/code you are using in the shell, and the input string/code you are using in the view. What happens if make a new empty Python script and cut and paste in your code (removing the wrap function from Django). Does it work then? James --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex problem in django
I'm sorry for my typo the string var suppose to be like this str = "wr:\n one bunny \n two bunny \n wr:\n three bunny \n So every match string "wr:" should had "+" in front of it line the one that confuse me is that my function work in django/python shell, but this regex doesn't work well if i called it from views.py of my django app So the problem that I faced is that, how come when using django/python shell. my regex work but not if I put in on my views.py Any hint? On Jun 29, 5:49 pm, James Gregory wrote: > On Jun 29, 11:19 am, Joru wrote: > > > ah, I just want to match in the end of line only > > so change the rule "wr$" would get what I want? > > > > Square brackets are for character groups, not literal strings. "wr:" > > > is just a string so it should be "wr:", not "[wr:]". Also, you want to > > > match the beginning of the line, not the end, so it should be > > > something like "^wr:", not "wr$". Unless I've missed something. > > When you split your test string on newlines you get: > > "wr:" > " one bunny" > " two bunny" > " wr: three bunny" > > In the first line "wr:" is at both the beginning and end of the > string, as it is the whole string. The next two lines do not feature > "wr:" at all. On the last line "wr:" is at neither the beginning nor > the end of the string - it has " " in front, and " three bunny" > afterwards. Depending on what you want to do you might want to call > strip() on each line, in which case the 4th line would become "wr: > three bunny", making wr: the beginning of the line. It depends what > you want to do, and anyway I can't write your program for you. > > Essentially, you just need to spend some time reading a bit more about > regular expressions:http://docs.python.org/library/re.html > > James --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex problem in django
On Jun 29, 11:19 am, Joru wrote: > ah, I just want to match in the end of line only > so change the rule "wr$" would get what I want? > > > Square brackets are for character groups, not literal strings. "wr:" > > is just a string so it should be "wr:", not "[wr:]". Also, you want to > > match the beginning of the line, not the end, so it should be > > something like "^wr:", not "wr$". Unless I've missed something. When you split your test string on newlines you get: "wr:" " one bunny" " two bunny" " wr: three bunny" In the first line "wr:" is at both the beginning and end of the string, as it is the whole string. The next two lines do not feature "wr:" at all. On the last line "wr:" is at neither the beginning nor the end of the string - it has " " in front, and " three bunny" afterwards. Depending on what you want to do you might want to call strip() on each line, in which case the 4th line would become "wr: three bunny", making wr: the beginning of the line. It depends what you want to do, and anyway I can't write your program for you. Essentially, you just need to spend some time reading a bit more about regular expressions: http://docs.python.org/library/re.html James --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex problem in django
ah, I just want to match in the end of line only so change the rule "wr$" would get what I want? On Jun 29, 4:56 pm, James Gregory wrote: > On Jun 29, 10:49 am, Joru wrote: > > > > > I mean None not null > > When I print rgx always None, that mean theregexeval never match > > The expected output result would be > > > +wr:> one bunny > > > two bunny > > > + wr: three bunny > > > Because everytime foundregexrules r'[wr:]$' then should add + in > > beginning of line > > > On Jun 29, 4:31 pm, James Gregory wrote: > > > > On Jun 29, 10:05 am, Joru wrote: > > > > > I still can't solve this > > > > Anyone had answer on this? > > > > > On Jun 26, 7:39 pm, Joru wrote: > > > > > > Hi, > > > > > > I experience some weirdness regarding usingregexwith django > > > > > I have following function in utils.py > > > > > > from django.utils.text import wrap > > > > > import re > > > > > > str = "wr: \n one bunny \n two bunny \n wr: three bunny \n > > > > > def do_regex(text): > > > > > lines = wrap(text, 55).split('\n') > > > > > for i, line in enumerate(lines): > > > > > cmp = re.compile(r'[wr:]$') > > > > > rgx = cmp.search(line) > > > > > if rgx: > > > > > line = "+%s" % line > > > > > lines[i] = line > > > > > else : > > > > > lines[i] = ">%s" % line > > > > > return '\n'.join(lines) > > > > > do_regex(str) > > > > > > when calling do_regex() from views.py, I always get rgx null while > > > > > when I use django shell rgx will have value when match toregexthat I > > > > > declare in cmp var > > > > > How to fix myregexso it can work inside views.py? > > > > I copied and pasted your code (with an added speech mark to close str) > > > into a controller function, and it works for me: > > > > Django version 1.1 beta 1, using settings 'pilchard.settings' > > > Development server is running athttp://127.0.0.1:8000/ > > > Quit the server with CTRL-BREAK.>wr: > > > > one bunny > > > > two bunny > > > > wr: three bunny > > > > [29/Jun/2009 10:29:45] "GET / HTTP/1.1" 200 2285 > > > > What do you mean by "get rgx null"? What exactly is null? Where? > > > > James > > Square brackets are for character groups, not literal strings. "wr:" > is just a string so it should be "wr:", not "[wr:]". Also, you want to > match the beginning of the line, not the end, so it should be > something like "^wr:", not "wr$". Unless I've missed something. > > James > James --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex problem in django
On Jun 29, 10:49 am, Joru wrote: > I mean None not null > When I print rgx always None, that mean the regex eval never match > The expected output result would be > > +wr:> one bunny > > two bunny > > + wr: three bunny > > Because everytime found regex rules r'[wr:]$' then should add + in > beginning of line > > On Jun 29, 4:31 pm, James Gregory wrote: > > > On Jun 29, 10:05 am, Joru wrote: > > > > I still can't solve this > > > Anyone had answer on this? > > > > On Jun 26, 7:39 pm, Joru wrote: > > > > > Hi, > > > > > I experience some weirdness regarding usingregexwith django > > > > I have following function in utils.py > > > > > from django.utils.text import wrap > > > > import re > > > > > str = "wr: \n one bunny \n two bunny \n wr: three bunny \n > > > > def do_regex(text): > > > > lines = wrap(text, 55).split('\n') > > > > for i, line in enumerate(lines): > > > > cmp = re.compile(r'[wr:]$') > > > > rgx = cmp.search(line) > > > > if rgx: > > > > line = "+%s" % line > > > > lines[i] = line > > > > else : > > > > lines[i] = ">%s" % line > > > > return '\n'.join(lines) > > > > do_regex(str) > > > > > when calling do_regex() from views.py, I always get rgx null while > > > > when I use django shell rgx will have value when match toregexthat I > > > > declare in cmp var > > > > How to fix myregexso it can work inside views.py? > > > I copied and pasted your code (with an added speech mark to close str) > > into a controller function, and it works for me: > > > Django version 1.1 beta 1, using settings 'pilchard.settings' > > Development server is running athttp://127.0.0.1:8000/ > > Quit the server with CTRL-BREAK.>wr: > > > one bunny > > > two bunny > > > wr: three bunny > > > [29/Jun/2009 10:29:45] "GET / HTTP/1.1" 200 2285 > > > What do you mean by "get rgx null"? What exactly is null? Where? > > > James > Square brackets are for character groups, not literal strings. "wr:" is just a string so it should be "wr:", not "[wr:]". Also, you want to match the beginning of the line, not the end, so it should be something like "^wr:", not "wr$". Unless I've missed something. James James --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex problem in django
I mean None not null When I print rgx always None, that mean the regex eval never match The expected output result would be +wr: > one bunny > two bunny + wr: three bunny Because everytime found regex rules r'[wr:]$' then should add + in beginning of line On Jun 29, 4:31 pm, James Gregory wrote: > On Jun 29, 10:05 am, Joru wrote: > > > > > I still can't solve this > > Anyone had answer on this? > > > On Jun 26, 7:39 pm, Joru wrote: > > > > Hi, > > > > I experience some weirdness regarding usingregexwith django > > > I have following function in utils.py > > > > from django.utils.text import wrap > > > import re > > > > str = "wr: \n one bunny \n two bunny \n wr: three bunny \n > > > def do_regex(text): > > > lines = wrap(text, 55).split('\n') > > > for i, line in enumerate(lines): > > > cmp = re.compile(r'[wr:]$') > > > rgx = cmp.search(line) > > > if rgx: > > > line = "+%s" % line > > > lines[i] = line > > > else : > > > lines[i] = ">%s" % line > > > return '\n'.join(lines) > > > do_regex(str) > > > > when calling do_regex() from views.py, I always get rgx null while > > > when I use django shell rgx will have value when match toregexthat I > > > declare in cmp var > > > How to fix myregexso it can work inside views.py? > > I copied and pasted your code (with an added speech mark to close str) > into a controller function, and it works for me: > > Django version 1.1 beta 1, using settings 'pilchard.settings' > Development server is running athttp://127.0.0.1:8000/ > Quit the server with CTRL-BREAK.>wr: > > one bunny > > two bunny > > wr: three bunny > > [29/Jun/2009 10:29:45] "GET / HTTP/1.1" 200 2285 > > What do you mean by "get rgx null"? What exactly is null? Where? > > James --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex problem in django
On Jun 29, 10:05 am, Joru wrote: > I still can't solve this > Anyone had answer on this? > > On Jun 26, 7:39 pm, Joru wrote: > > > Hi, > > > I experience some weirdness regarding usingregexwith django > > I have following function in utils.py > > > from django.utils.text import wrap > > import re > > > str = "wr: \n one bunny \n two bunny \n wr: three bunny \n > > def do_regex(text): > > lines = wrap(text, 55).split('\n') > > for i, line in enumerate(lines): > > cmp = re.compile(r'[wr:]$') > > rgx = cmp.search(line) > > if rgx: > > line = "+%s" % line > > lines[i] = line > > else : > > lines[i] = ">%s" % line > > return '\n'.join(lines) > > do_regex(str) > > > when calling do_regex() from views.py, I always get rgx null while > > when I use django shell rgx will have value when match toregexthat I > > declare in cmp var > > How to fix myregexso it can work inside views.py? I copied and pasted your code (with an added speech mark to close str) into a controller function, and it works for me: Django version 1.1 beta 1, using settings 'pilchard.settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK. >wr: > one bunny > two bunny > wr: three bunny > [29/Jun/2009 10:29:45] "GET / HTTP/1.1" 200 2285 What do you mean by "get rgx null"? What exactly is null? Where? James --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex problem in django
I still can't solve this Anyone had answer on this? On Jun 26, 7:39 pm, Joru wrote: > Hi, > > I experience some weirdness regarding usingregexwith django > I have following function in utils.py > > from django.utils.text import wrap > import re > > str = "wr: \n one bunny \n two bunny \n wr: three bunny \n > def do_regex(text): > lines = wrap(text, 55).split('\n') > for i, line in enumerate(lines): > cmp = re.compile(r'[wr:]$') > rgx = cmp.search(line) > if rgx: > line = "+%s" % line > lines[i] = line > else : > lines[i] = ">%s" % line > return '\n'.join(lines) > do_regex(str) > > when calling do_regex() from views.py, I always get rgx null while > when I use django shell rgx will have value when match toregexthat I > declare in cmp var > How to fix myregexso it can work inside views.py? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex pattern for URL matching
I think this is related to WSGI. On Oct 6, 7:17 pm, Merrick <[EMAIL PROTECTED]> wrote: > That is the approach I took and how I resolved the original problem > with the 404. It led me to find that "AllowEncodedSlashes On" in > Apache is needed for encoded slashes to be allowed in the pathname > information following the filename. > > The problem now is that > > http%3A%2F%2F prints http:/ in my template, > > http%3A%2F also prints out as http:/ > > The second encoded forward slash is being omitted. > > http%3A%2F$2Fwww.wired.com%2Fprints http:/www.wired.com/ > > http%3A%2F$2Fwww.wired.com%2F%2Falso prints http:/www.wired.com/ > > Thanks for looking at this. > > On Oct 6, 5:56 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> > wrote: > > > On Mon, 2008-10-06 at 16:10 -0700, Merrick wrote: > > > keith, thanks for trying. > > > > %2f is the encoded value of /, but urls contain other characters as > > > well not just alphanumeric. > > > I think you're debugging the wrong piece of the problem here. Your > > original regular expression must have been pretty close to the right > > answer, although since it wasn't a valid reg-exp (mis-matched > > parentheses, it's hard to tell). Using "." to match "any character" was > > the right approach. > > > I would start debugging this by trying a simpler example. You said the > > pattern matched "www.wired.com" and then leapt straight to "http%3A%2F% > > 2Fwww.wired.com%2F". So what about something in between, say "%3A" or > > just "www.wored.com%2F". > > > Also, where do things fail? Does the regular expression not match > > anything or does the view not finish for some reason (i.e. do you know > > for sure that the view isn't being called)? Because, again, your > > original regular expression, once you fix the syntax error, looks like > > it should work correctly. > > > Go back to the start, fix the error with the missing parenthese, start > > from something you know works and then add one character at a time until > > it fails. Put debugging prints in your view so that you know if the view > > gets called or not. > > > Regards, > > Malcolm > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex pattern for URL matching
That is the approach I took and how I resolved the original problem with the 404. It led me to find that "AllowEncodedSlashes On" in Apache is needed for encoded slashes to be allowed in the pathname information following the filename. The problem now is that http%3A%2F%2F prints http:/ in my template, http%3A%2F also prints out as http:/ The second encoded forward slash is being omitted. http%3A%2F$2Fwww.wired.com%2F prints http:/www.wired.com/ http%3A%2F$2Fwww.wired.com%2F%2F also prints http:/www.wired.com/ Thanks for looking at this. On Oct 6, 5:56 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Mon, 2008-10-06 at 16:10 -0700, Merrick wrote: > > keith, thanks for trying. > > > %2f is the encoded value of /, but urls contain other characters as > > well not just alphanumeric. > > I think you're debugging the wrong piece of the problem here. Your > original regular expression must have been pretty close to the right > answer, although since it wasn't a valid reg-exp (mis-matched > parentheses, it's hard to tell). Using "." to match "any character" was > the right approach. > > I would start debugging this by trying a simpler example. You said the > pattern matched "www.wired.com" and then leapt straight to "http%3A%2F% > 2Fwww.wired.com%2F". So what about something in between, say "%3A" or > just "www.wored.com%2F". > > Also, where do things fail? Does the regular expression not match > anything or does the view not finish for some reason (i.e. do you know > for sure that the view isn't being called)? Because, again, your > original regular expression, once you fix the syntax error, looks like > it should work correctly. > > Go back to the start, fix the error with the missing parenthese, start > from something you know works and then add one character at a time until > it fails. Put debugging prints in your view so that you know if the view > gets called or not. > > Regards, > Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex pattern for URL matching
On Mon, 2008-10-06 at 16:10 -0700, Merrick wrote: > keith, thanks for trying. > > %2f is the encoded value of /, but urls contain other characters as > well not just alphanumeric. I think you're debugging the wrong piece of the problem here. Your original regular expression must have been pretty close to the right answer, although since it wasn't a valid reg-exp (mis-matched parentheses, it's hard to tell). Using "." to match "any character" was the right approach. I would start debugging this by trying a simpler example. You said the pattern matched "www.wired.com" and then leapt straight to "http%3A%2F% 2Fwww.wired.com%2F". So what about something in between, say "%3A" or just "www.wored.com%2F". Also, where do things fail? Does the regular expression not match anything or does the view not finish for some reason (i.e. do you know for sure that the view isn't being called)? Because, again, your original regular expression, once you fix the syntax error, looks like it should work correctly. Go back to the start, fix the error with the missing parenthese, start from something you know works and then add one character at a time until it fails. Put debugging prints in your view so that you know if the view gets called or not. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex pattern for URL matching
While I have not found the complete solution, I am closer. I added this to my apache settings for the virtual host: AllowEncodedSlashes On I am no longer getting a 404. But even though the url has two instances of %2f to represent two slashes: http://mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F I am able to capture the URL, but with only one slash. I pass it to my ModelForm and it prints in my template as: http:/www.wired.com/ Note the lack of double forward slashes after the colon. On Oct 6, 4:10 pm, Merrick <[EMAIL PROTECTED]> wrote: > keith, thanks for trying. > > %2f is the encoded value of /, but urls contain other characters as > well not just alphanumeric. > > I suspect this issue may have to do with apache or WSGI but not sure > what. > > On Oct 6, 4:06 pm, "Keith Eberle" <[EMAIL PROTECTED]> wrote: > > > quick solution, i think you could add the % to the regex (i'm hardly a > > regex master): > > > r'^find/(?P[%-\w]+)$ > > > keith > > > On Mon, Oct 6, 2008 at 7:05 PM, Merrick <[EMAIL PROTECTED]> wrote: > > > > I have narrowed down the problem to %2F in my url, anyone? > > > > On Oct 6, 2:55 pm, Merrick <[EMAIL PROTECTED]> wrote: > > > > \w will only match alphanumeric characters, I need to match anything > > > > and will let my modelform verify that it is indeed a URL. > > > > > On Oct 6, 2:43 pm, Merrick <[EMAIL PROTECTED]> wrote: > > > > > > Thank you, I meant urls.py. APPEND_SLASH = False so I omitted the > > > > > trailing slash from the regex line: > > > > > > r'^find/(?P[-\w]+)$ > > > > > > and if I pull up the address: > > > > > >http://mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F > > > > > > I still get > > > > > > Not Found > > > > > > The requested URL /find/http://www.wired.com/wasnotfoundon this > > > > > server. > > > > > > I did figure out how to decode the URL in python using unquote_plus(), > > > > > but I cannot figure out this problem. > > > > > > On Oct 6, 1:27 pm, "Keith Eberle" <[EMAIL PROTECTED]> wrote: > > > > > > > it looks like you have mismatched parens, and no trailing slash, > > > which will > > > > > > matter if APPEND_SLASH = True. the regex should look like: > > > > > > > r'^find/(?P[-\w]+)/$' > > > > > > > should be urls.py too, not views.py. > > > > > > > keith > > > > > > > On Mon, Oct 6, 2008 at 1:17 PM, Merrick <[EMAIL PROTECTED]> wrote: > > > > > > > > I am trying to figure out how to match / capture a URL. > > > > > > > > views.py > > > > > > > === > > > > > > > urlpatterns = patterns('', > > > > > > > url(r'^find/(?P(.*)$', > > > > > > > view = 'myapp.views.find', > > > > > > > name = 'find' > > > > > > > ), > > > > > > > > when I enter in this address: > > > > > > > > mydomain.com/find/www.wired.com > > > > > > > > my view / template are executed, but if I do this: > > > > > > > > mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F > > > > > > > > I get: > > > > > > > > Not Found > > > > > > > > The requested URL /find/http://www.wired.com/wasnotfoundonthis > > > > > > > server. > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex pattern for URL matching
keith, thanks for trying. %2f is the encoded value of /, but urls contain other characters as well not just alphanumeric. I suspect this issue may have to do with apache or WSGI but not sure what. On Oct 6, 4:06 pm, "Keith Eberle" <[EMAIL PROTECTED]> wrote: > quick solution, i think you could add the % to the regex (i'm hardly a > regex master): > > r'^find/(?P[%-\w]+)$ > > keith > > On Mon, Oct 6, 2008 at 7:05 PM, Merrick <[EMAIL PROTECTED]> wrote: > > > I have narrowed down the problem to %2F in my url, anyone? > > > On Oct 6, 2:55 pm, Merrick <[EMAIL PROTECTED]> wrote: > > > \w will only match alphanumeric characters, I need to match anything > > > and will let my modelform verify that it is indeed a URL. > > > > On Oct 6, 2:43 pm, Merrick <[EMAIL PROTECTED]> wrote: > > > > > Thank you, I meant urls.py. APPEND_SLASH = False so I omitted the > > > > trailing slash from the regex line: > > > > > r'^find/(?P[-\w]+)$ > > > > > and if I pull up the address: > > > > >http://mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F > > > > > I still get > > > > > Not Found > > > > > The requested URL /find/http://www.wired.com/wasnotfound on this > > > > server. > > > > > I did figure out how to decode the URL in python using unquote_plus(), > > > > but I cannot figure out this problem. > > > > > On Oct 6, 1:27 pm, "Keith Eberle" <[EMAIL PROTECTED]> wrote: > > > > > > it looks like you have mismatched parens, and no trailing slash, > > which will > > > > > matter if APPEND_SLASH = True. the regex should look like: > > > > > > r'^find/(?P[-\w]+)/$' > > > > > > should be urls.py too, not views.py. > > > > > > keith > > > > > > On Mon, Oct 6, 2008 at 1:17 PM, Merrick <[EMAIL PROTECTED]> wrote: > > > > > > > I am trying to figure out how to match / capture a URL. > > > > > > > views.py > > > > > > === > > > > > > urlpatterns = patterns('', > > > > > > url(r'^find/(?P(.*)$', > > > > > > view = 'myapp.views.find', > > > > > > name = 'find' > > > > > > ), > > > > > > > when I enter in this address: > > > > > > > mydomain.com/find/www.wired.com > > > > > > > my view / template are executed, but if I do this: > > > > > > > mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F > > > > > > > I get: > > > > > > > Not Found > > > > > > > The requested URL /find/http://www.wired.com/wasnotfoundon this > > > > > > server. > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex pattern for URL matching
quick solution, i think you could add the % to the regex (i'm hardly a regex master): r'^find/(?P[%-\w]+)$ keith On Mon, Oct 6, 2008 at 7:05 PM, Merrick <[EMAIL PROTECTED]> wrote: > > I have narrowed down the problem to %2F in my url, anyone? > > > > On Oct 6, 2:55 pm, Merrick <[EMAIL PROTECTED]> wrote: > > \w will only match alphanumeric characters, I need to match anything > > and will let my modelform verify that it is indeed a URL. > > > > On Oct 6, 2:43 pm, Merrick <[EMAIL PROTECTED]> wrote: > > > > > Thank you, I meant urls.py. APPEND_SLASH = False so I omitted the > > > trailing slash from the regex line: > > > > > r'^find/(?P[-\w]+)$ > > > > > and if I pull up the address: > > > > >http://mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F > > > > > I still get > > > > > Not Found > > > > > The requested URL /find/http://www.wired.com/wasnot found on this > > > server. > > > > > I did figure out how to decode the URL in python using unquote_plus(), > > > but I cannot figure out this problem. > > > > > On Oct 6, 1:27 pm, "Keith Eberle" <[EMAIL PROTECTED]> wrote: > > > > > > it looks like you have mismatched parens, and no trailing slash, > which will > > > > matter if APPEND_SLASH = True. the regex should look like: > > > > > > r'^find/(?P[-\w]+)/$' > > > > > > should be urls.py too, not views.py. > > > > > > keith > > > > > > On Mon, Oct 6, 2008 at 1:17 PM, Merrick <[EMAIL PROTECTED]> wrote: > > > > > > > I am trying to figure out how to match / capture a URL. > > > > > > > views.py > > > > > === > > > > > urlpatterns = patterns('', > > > > >url(r'^find/(?P(.*)$', > > > > >view = 'myapp.views.find', > > > > >name = 'find' > > > > >), > > > > > > > when I enter in this address: > > > > > > > mydomain.com/find/www.wired.com > > > > > > > my view / template are executed, but if I do this: > > > > > > > mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F > > > > > > > I get: > > > > > > > Not Found > > > > > > > The requested URL /find/http://www.wired.com/wasnotfound on this > > > > > server. > > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex pattern for URL matching
I have narrowed down the problem to %2F in my url, anyone? On Oct 6, 2:55 pm, Merrick <[EMAIL PROTECTED]> wrote: > \w will only match alphanumeric characters, I need to match anything > and will let my modelform verify that it is indeed a URL. > > On Oct 6, 2:43 pm, Merrick <[EMAIL PROTECTED]> wrote: > > > Thank you, I meant urls.py. APPEND_SLASH = False so I omitted the > > trailing slash from the regex line: > > > r'^find/(?P[-\w]+)$ > > > and if I pull up the address: > > >http://mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F > > > I still get > > > Not Found > > > The requested URL /find/http://www.wired.com/wasnot found on this > > server. > > > I did figure out how to decode the URL in python using unquote_plus(), > > but I cannot figure out this problem. > > > On Oct 6, 1:27 pm, "Keith Eberle" <[EMAIL PROTECTED]> wrote: > > > > it looks like you have mismatched parens, and no trailing slash, which > > > will > > > matter if APPEND_SLASH = True. the regex should look like: > > > > r'^find/(?P[-\w]+)/$' > > > > should be urls.py too, not views.py. > > > > keith > > > > On Mon, Oct 6, 2008 at 1:17 PM, Merrick <[EMAIL PROTECTED]> wrote: > > > > > I am trying to figure out how to match / capture a URL. > > > > > views.py > > > > === > > > > urlpatterns = patterns('', > > > > url(r'^find/(?P(.*)$', > > > > view = 'myapp.views.find', > > > > name = 'find' > > > > ), > > > > > when I enter in this address: > > > > > mydomain.com/find/www.wired.com > > > > > my view / template are executed, but if I do this: > > > > > mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F > > > > > I get: > > > > > Not Found > > > > > The requested URL /find/http://www.wired.com/wasnotfound on this > > > > server. > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex pattern for URL matching
Thank you, I meant urls.py. APPEND_SLASH = False so I omitted the trailing slash from the regex line: r'^find/(?P[-\w]+)$ and if I pull up the address: http://mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F I still get Not Found The requested URL /find/http://www.wired.com/ was not found on this server. I did figure out how to decode the URL in python using unquote_plus(), but I cannot figure out this problem. On Oct 6, 1:27 pm, "Keith Eberle" <[EMAIL PROTECTED]> wrote: > it looks like you have mismatched parens, and no trailing slash, which will > matter if APPEND_SLASH = True. the regex should look like: > > r'^find/(?P[-\w]+)/$' > > should be urls.py too, not views.py. > > keith > > On Mon, Oct 6, 2008 at 1:17 PM, Merrick <[EMAIL PROTECTED]> wrote: > > > I am trying to figure out how to match / capture a URL. > > > views.py > > === > > urlpatterns = patterns('', > > url(r'^find/(?P(.*)$', > > view = 'myapp.views.find', > > name = 'find' > > ), > > > when I enter in this address: > > > mydomain.com/find/www.wired.com > > > my view / template are executed, but if I do this: > > > mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F > > > I get: > > > Not Found > > > The requested URL /find/http://www.wired.com/was not found on this > > server. > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex pattern for URL matching
\w will only match alphanumeric characters, I need to match anything and will let my modelform verify that it is indeed a URL. On Oct 6, 2:43 pm, Merrick <[EMAIL PROTECTED]> wrote: > Thank you, I meant urls.py. APPEND_SLASH = False so I omitted the > trailing slash from the regex line: > > r'^find/(?P[-\w]+)$ > > and if I pull up the address: > > http://mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F > > I still get > > Not Found > > The requested URL /find/http://www.wired.com/was not found on this > server. > > I did figure out how to decode the URL in python using unquote_plus(), > but I cannot figure out this problem. > > On Oct 6, 1:27 pm, "Keith Eberle" <[EMAIL PROTECTED]> wrote: > > > it looks like you have mismatched parens, and no trailing slash, which will > > matter if APPEND_SLASH = True. the regex should look like: > > > r'^find/(?P[-\w]+)/$' > > > should be urls.py too, not views.py. > > > keith > > > On Mon, Oct 6, 2008 at 1:17 PM, Merrick <[EMAIL PROTECTED]> wrote: > > > > I am trying to figure out how to match / capture a URL. > > > > views.py > > > === > > > urlpatterns = patterns('', > > > url(r'^find/(?P(.*)$', > > > view = 'myapp.views.find', > > > name = 'find' > > > ), > > > > when I enter in this address: > > > > mydomain.com/find/www.wired.com > > > > my view / template are executed, but if I do this: > > > > mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F > > > > I get: > > > > Not Found > > > > The requested URL /find/http://www.wired.com/wasnot found on this > > > server. > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex pattern for URL matching
it looks like you have mismatched parens, and no trailing slash, which will matter if APPEND_SLASH = True. the regex should look like: r'^find/(?P[-\w]+)/$' should be urls.py too, not views.py. keith On Mon, Oct 6, 2008 at 1:17 PM, Merrick <[EMAIL PROTECTED]> wrote: > > I am trying to figure out how to match / capture a URL. > > views.py > === > urlpatterns = patterns('', >url(r'^find/(?P(.*)$', >view = 'myapp.views.find', >name = 'find' >), > > when I enter in this address: > > mydomain.com/find/www.wired.com > > my view / template are executed, but if I do this: > > mydomain.com/find/http%3A%2F%2Fwww.wired.com%2F > > I get: > > Not Found > > The requested URL /find/http://www.wired.com/ was not found on this > server. > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex
On Jul 2, 5:33 pm, Ross Dakin <[EMAIL PROTECTED]> wrote: > Followup to clarify. > > If you DON'T use a is_longdistance flag in the model, then you use a > set of rules to determine if a number is long distance when you get > the number out of the db. Sure. Now what if the set of rules you need to use don't fit in "naturally" into the RDBMS layer? For example, a regex search in a field is, obviously, not the most efficient way to determine long distance-ness of a phone number record if you have say a million phone numbers. RegEx searches tend to be CPU-intensive and having to perform them over and over to determine the value of an important/frequently needed attribute is not necessarily the best design choice. > > You can avoid this by using a is_longdistance flag in the model, but > you're going to have to do the same thing to determine whether or not > to set the flag when you insert a number into the database. Yes, but you would need to do it only once per record insert/update. It's typical for most systems to perform far more DB record retrievals than DB record updates. So, a modestly expensive operation when repeated millions of times does call out for a proper design choice (compute on retrieval vs. compute on save.) > And you > have the added pain of updating the db is these rules change, which > you don't have to do if you just check for long-distance-ness upon > retrieval. Again, the pain is relative to the design of the application and DB. You could, for example, have a DB trigger update that flag for you transparently. You could, for example, also establish an architecture where DB updates go through a stored procedure or a framework's ORM layer and hook in any pre-computations there. > > We could even argue that the flag is wasted space in the db. Arguing that would be wasted usenet space in today's day and age :) > > But if we get that nit picky, one could counter-argue that running the > is-long-distance logic once upon insertion is more efficient than > running it on each retrieval in a read-intensive system. However, I > prefer and human-efficient practices over computer-efficient > practices; computers get faster, humans don't. > > Thus, the cleanliness and (IMHO) elegance of simply doing the check > upon retrieval and thereby avoiding potential manual updates to the db > and introducing a new table field beats the alternative. You would be right if this were a simple check that's naturally efficient in SQL. But a regex check doesn't fall in that category especially a regex check that has many different OR conditions and especially one that might be run over millions of phone records. > > Sorry again: huge tangent. I don't think it is. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex
You might want to refer to this recent article at Coding Horror: http://www.codinghorror.com/blog/archives/001016.html I would stick to what you have. (and I would also only do the calculation once and store it as a boolean field in the database as suggested : ) John On Jun 30, 7:13 am, mike171562 <[EMAIL PROTECTED]> wrote: > Hello, > I am working on a django that querys long distance numbers from a > mysql database. I am currently using the django API, that goes > something like this. > > long_distance = > Call.objects.filter(dest_num__startswith='1').filter(dest_num__gt=6).exclude(dest_num__startswith='18').exclude(dest_num__startswith='1281').exclude(dest_num__startswith='1832').exclude(dest_num__startswith='1713') > > I was hoping to consolidate all of my .filter excludes into one regex. > is this possible and would it be more efficient? Basically any number > that doesnt start with 281,713,832 or 1281,1713,or 1832 is long > distance any help would be appreciated. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex
Hi Rajesh, Certainly, best practices are subject to your goals: code maintainability, storage efficiency, execution efficiency, etc. I agree, there are times when it makes sense to store calculated values in a database. I would argue, however, that this inhibits scalability. As a system grows, the potential for inconsistencies due to this redundant data also grows. We have this issue at my current job right now. Our systems have grown organically over five years and we have various pools of redundant data that have been the sources of some scaling issues. Ross On Jul 2, 2:27 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote: > Hi Ross, > > > > > I would disagree here. The database should only be used to store raw > > data; the database should not know anything about this data (the > > database should not be "smart"). > > > Determining whether or not a number qualifies as "long distance" is a > > job for the domain / controller / view layer (pick your jargon). > > > Here's why. Suppose the company moves, or the geographical scope of > > one area code is changed. Now you have a different set of rules that > > determine what qualifies a number as being "long distance." Would you > > rather change the rule with one line of code in your view, or > > construct and run some SQL that finds and updated all matching phone > > numbers? (Note: this is meant to be a rhetorical question but could > > very well be debated.) > > > Sorry for the tangent. I'm a stickler for best practices. > > That's fair...and although, you meant that as a rhetorical question, I > would indeed debate that and would further argue with your definition > of what constitutes best practices as implied by your post. > > Best practices don't exist in one dimension and they are not written > in stone. You can have best practices for high performance, highly > scalable applications that are different from best practices for > "regular" applications. Today's scalability needs demand that > developers keep an open mind on what's best for the application and > it's performance/scalability requirements. Most of the time, this is > not a problem as theory usually converges with practice for a lot of > applications. But not for all. > > When, for example, a regex based query is very expensive and your app > has many places where it wants to pull up phone numbers based on their > "is_long_distance" value, it certainly makes sense to store this > attribute in a precomputed form and refreshed it in a batch > computation if/when the rules for it change at all in future. > > Another example, if you have a model with a purchase order with child > items that represent each purchased item, it does make sense to store > the order total in the purchase order master record, even though you > could derive it from the sum of individual item totals every time you > need it. > > -Rajesh D --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex
Followup to clarify. If you DON'T use a is_longdistance flag in the model, then you use a set of rules to determine if a number is long distance when you get the number out of the db. You can avoid this by using a is_longdistance flag in the model, but you're going to have to do the same thing to determine whether or not to set the flag when you insert a number into the database. And you have the added pain of updating the db is these rules change, which you don't have to do if you just check for long-distance-ness upon retrieval. We could even argue that the flag is wasted space in the db. But if we get that nit picky, one could counter-argue that running the is-long-distance logic once upon insertion is more efficient than running it on each retrieval in a read-intensive system. However, I prefer and human-efficient practices over computer-efficient practices; computers get faster, humans don't. Thus, the cleanliness and (IMHO) elegance of simply doing the check upon retrieval and thereby avoiding potential manual updates to the db and introducing a new table field beats the alternative. Sorry again: huge tangent. Ross --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex
Hi Ross, > I would disagree here. The database should only be used to store raw > data; the database should not know anything about this data (the > database should not be "smart"). > > Determining whether or not a number qualifies as "long distance" is a > job for the domain / controller / view layer (pick your jargon). > > Here's why. Suppose the company moves, or the geographical scope of > one area code is changed. Now you have a different set of rules that > determine what qualifies a number as being "long distance." Would you > rather change the rule with one line of code in your view, or > construct and run some SQL that finds and updated all matching phone > numbers? (Note: this is meant to be a rhetorical question but could > very well be debated.) > > Sorry for the tangent. I'm a stickler for best practices. That's fair...and although, you meant that as a rhetorical question, I would indeed debate that and would further argue with your definition of what constitutes best practices as implied by your post. Best practices don't exist in one dimension and they are not written in stone. You can have best practices for high performance, highly scalable applications that are different from best practices for "regular" applications. Today's scalability needs demand that developers keep an open mind on what's best for the application and it's performance/scalability requirements. Most of the time, this is not a problem as theory usually converges with practice for a lot of applications. But not for all. When, for example, a regex based query is very expensive and your app has many places where it wants to pull up phone numbers based on their "is_long_distance" value, it certainly makes sense to store this attribute in a precomputed form and refreshed it in a batch computation if/when the rules for it change at all in future. Another example, if you have a model with a purchase order with child items that represent each purchased item, it does make sense to store the order total in the purchase order master record, even though you could derive it from the sum of individual item totals every time you need it. -Rajesh D --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex
> If you have the ability to change your Call model, you should consider > adding a new BooleanField called "is_long_distance" to Call. Then, you > only have to compute it (in Call.save()) when you save or change a > number. That will make your query very simple and efficient. > > -Rajesh D I would disagree here. The database should only be used to store raw data; the database should not know anything about this data (the database should not be "smart"). Determining whether or not a number qualifies as "long distance" is a job for the domain / controller / view layer (pick your jargon). Here's why. Suppose the company moves, or the geographical scope of one area code is changed. Now you have a different set of rules that determine what qualifies a number as being "long distance." Would you rather change the rule with one line of code in your view, or construct and run some SQL that finds and updated all matching phone numbers? (Note: this is meant to be a rhetorical question but could very well be debated.) Sorry for the tangent. I'm a stickler for best practices. Cheers, Ross --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex assistance
Gul, That was it, thx a bunch.. On Jul 1, 10:27 am, "Marty Alchin" <[EMAIL PROTECTED]> wrote: > On Tue, Jul 1, 2008 at 11:15 AM, John Lenton <[EMAIL PROTECTED]> wrote: > >> local numbers start with 281, 832, 713 , or 1281, 1832, or 1713, my > >> regex which isnt working looks like this > > > in other words, local numbers match the regex > > > r'^(?:281|832|713|1281|1832|1713)' > > Or, to simplify it even further, and make it easier to add new area > codes later on, if any crop up: > > r'^1?(281|832|713)' > > -Gul --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex assistance
On Tue, Jul 1, 2008 at 11:15 AM, John Lenton <[EMAIL PROTECTED]> wrote: >> local numbers start with 281, 832, 713 , or 1281, 1832, or 1713, my >> regex which isnt working looks like this > > in other words, local numbers match the regex > > r'^(?:281|832|713|1281|1832|1713)' Or, to simplify it even further, and make it easier to add new area codes later on, if any crop up: r'^1?(281|832|713)' -Gul --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex assistance
On Tue, Jul 1, 2008 at 12:12, mike171562 <[EMAIL PROTECTED]> wrote: > > Hello, > I am trying to build a regex for a query that excludes local phone > numbers from a list of calls thus leaving only long distance. I dont > have alot of experience with the "re" module > > local numbers start with 281, 832, 713 , or 1281, 1832, or 1713, my > regex which isnt working looks like this in other words, local numbers match the regex r'^(?:281|832|713|1281|1832|1713)' -- John Lenton ([EMAIL PROTECTED]) -- Random fortune: The trouble with a lot of self-made men is that they worship their creator. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex
Not that I know of, in the event you need it you can also import QNot from the same place as Q and it does the same thing as ~Q On Jun 30, 12:48 pm, mike171562 <[EMAIL PROTECTED]> wrote: > just wondering, would there be a difference in performance between > using .exclude without the negation or .filter( with the negation? > > On Jun 30, 12:33 pm, Ayaz Ahmed Khan <[EMAIL PROTECTED]> > wrote: > > > On Jun 30, 10:27 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > > > > Negation of Q objects is a recent addition > > > (seehttp://code.djangoproject.com/ticket/4858). You must be using a > > > post-queryset-refactor SVN checkout while the original poster is probably > > > using a 0.96 release (or an SVN checkout more than a few months old). > > > Thanks. You are spot on. I am working with a very recent SVN build > > of Django. I did not know the negation feature in Q objects is > > something that was only recently added. > > > -- > > Ayaz Ahmed Khan > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex
just wondering, would there be a difference in performance between using .exclude without the negation or .filter( with the negation? On Jun 30, 12:33 pm, Ayaz Ahmed Khan <[EMAIL PROTECTED]> wrote: > On Jun 30, 10:27 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > > > > > Negation of Q objects is a recent addition > > (seehttp://code.djangoproject.com/ticket/4858). You must be using a > > post-queryset-refactor SVN checkout while the original poster is probably > > using a 0.96 release (or an SVN checkout more than a few months old). > > Thanks. You are spot on. I am working with a very recent SVN build > of Django. I did not know the negation feature in Q objects is > something that was only recently added. > > -- > Ayaz Ahmed Khan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex
On Jun 30, 10:27 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > > Negation of Q objects is a recent addition > (seehttp://code.djangoproject.com/ticket/4858). You must be using a > post-queryset-refactor SVN checkout while the original poster is probably > using a 0.96 release (or an SVN checkout more than a few months old). > Thanks. You are spot on. I am working with a very recent SVN build of Django. I did not know the negation feature in Q objects is something that was only recently added. -- Ayaz Ahmed Khan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex
On Mon, Jun 30, 2008 at 12:27 PM, Ayaz Ahmed Khan <[EMAIL PROTECTED]> wrote: > > On Jun 30, 9:08 pm, mike171562 <[EMAIL PROTECTED]> wrote: > > Thanks that works well, but when I try to use the ~ as you suggested I > > get the error > > ""bad operand type for unary ~: 'Q'"" > > so i removed the ~ and changed 'filter' to 'exclude' > > > > That is weird. The negation operator works fine here with the Q > syntax: > > In [15]: Bringer.objects.filter(~Q(buyer__user__id=2) & > ~Q(buyer__user__id=3)) > Out[15]: [] > Negation of Q objects is a recent addition (see http://code.djangoproject.com/ticket/4858). You must be using a post-queryset-refactor SVN checkout while the original poster is probably using a 0.96 release (or an SVN checkout more than a few months old). Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex
On Jun 30, 9:08 pm, mike171562 <[EMAIL PROTECTED]> wrote: > Thanks that works well, but when I try to use the ~ as you suggested I > get the error > ""bad operand type for unary ~: 'Q'"" > so i removed the ~ and changed 'filter' to 'exclude' > That is weird. The negation operator works fine here with the Q syntax: In [15]: Bringer.objects.filter(~Q(buyer__user__id=2) & ~Q(buyer__user__id=3)) Out[15]: [] -- Ayaz Ahmed Khan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex
Thanks that works well, but when I try to use the ~ as you suggested I get the error ""bad operand type for unary ~: 'Q'"" so i removed the ~ and changed 'filter' to 'exclude' On Jun 30, 9:53 am, Ayaz Ahmed Khan <[EMAIL PROTECTED]> wrote: > On Jun 30, 7:13 pm, mike171562 <[EMAIL PROTECTED]> wrote: > > > Hello, > >I am working on a django that querys long distance numbers from a > > mysql database. I am currently using the django API, that goes > > something like this. > > > long_distance = > > Call.objects.filter(dest_num__startswith='1').filter(dest_num__gt=6).exclude(dest_num__startswith='18').exclude(dest_num__startswith='1281').exclude(dest_num__startswith='1832').exclude(dest_num__startswith='1713') > > > I was hoping to consolidate all of my .filter excludes into one regex. > > is this possible and would it be more efficient? Basically any number > > that doesnt start with 281,713,832 or 1281,1713,or 1832 is long > > distance any help would be appreciated. > > Using regex mostly complicates things. If I have understood your > requirement properly, the following may be a better and cleaner > alternative: > > from django.models import Q > > long_distance = Call.objects.filter( > > ~Q(dest_num__startswith='281') & > > ~Q(dest_num__startswith='713') & > > ~Q(dest_num__startswith='832') & > > ~Q(dest_num__startswith='1281') & > > ~Q(dest_num__startswith='1713') & > > ~Q(dest_num__startswith='1832 ') > ) > > That is merely an example. You can make up different conditionals > with the use of the Q > feature.http://www.djangoproject.com/documentation/db-api/#complex-lookups-wi... > > -- > Ayaz Ahmed Khan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex
On Jun 30, 7:13 pm, mike171562 <[EMAIL PROTECTED]> wrote: > Hello, > I am working on a django that querys long distance numbers from a > mysql database. I am currently using the django API, that goes > something like this. > > long_distance = > Call.objects.filter(dest_num__startswith='1').filter(dest_num__gt=6).exclude(dest_num__startswith='18').exclude(dest_num__startswith='1281').exclude(dest_num__startswith='1832').exclude(dest_num__startswith='1713') > > I was hoping to consolidate all of my .filter excludes into one regex. > is this possible and would it be more efficient? Basically any number > that doesnt start with 281,713,832 or 1281,1713,or 1832 is long > distance any help would be appreciated. Using regex mostly complicates things. If I have understood your requirement properly, the following may be a better and cleaner alternative: from django.models import Q long_distance = Call.objects.filter( ~Q(dest_num__startswith='281') & ~Q(dest_num__startswith='713') & ~Q(dest_num__startswith='832') & ~Q(dest_num__startswith='1281') & ~Q(dest_num__startswith='1713') & ~Q(dest_num__startswith='1832 ') ) That is merely an example. You can make up different conditionals with the use of the Q feature. http://www.djangoproject.com/documentation/db-api/#complex-lookups-with-q-objects -- Ayaz Ahmed Khan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex
Rajesh D, That would be much simpler, but this is a pre-existing database of call records. thanks On Jun 30, 9:35 am, Rajesh Dhawan <[EMAIL PROTECTED]> wrote: > Hi Mike, > > >I am working on a django that querys long distance numbers from a > > mysql database. I am currently using the django API, that goes > > something like this. > > > long_distance = > > Call.objects.filter(dest_num__startswith='1').filter(dest_num__gt=6).exclude(dest_num__startswith='18').exclude(dest_num__startswith='1281').exclude(dest_num__startswith='1832').exclude(dest_num__startswith='1713') > > > I was hoping to consolidate all of my .filter excludes into one regex. > > is this possible and would it be more efficient? Basically any number > > that doesnt start with 281,713,832 or 1281,1713,or 1832 is long > > distance any help would be appreciated. > > If you have the ability to change your Call model, you should consider > adding a new BooleanField called "is_long_distance" to Call. Then, you > only have to compute it (in Call.save()) when you save or change a > number. That will make your query very simple and efficient. > > -Rajesh D --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex
Hi Mike, >I am working on a django that querys long distance numbers from a > mysql database. I am currently using the django API, that goes > something like this. > > long_distance = > Call.objects.filter(dest_num__startswith='1').filter(dest_num__gt=6).exclude(dest_num__startswith='18').exclude(dest_num__startswith='1281').exclude(dest_num__startswith='1832').exclude(dest_num__startswith='1713') > > I was hoping to consolidate all of my .filter excludes into one regex. > is this possible and would it be more efficient? Basically any number > that doesnt start with 281,713,832 or 1281,1713,or 1832 is long > distance any help would be appreciated. If you have the ability to change your Call model, you should consider adding a new BooleanField called "is_long_distance" to Call. Then, you only have to compute it (in Call.save()) when you save or change a number. That will make your query very simple and efficient. -Rajesh D --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex works in python, not in django
thanks! dumb mistake On May 23, 7:42 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > On Fri, May 23, 2008 at 10:36 PM, skunkwerk <[EMAIL PROTECTED]> wrote: > > > I'm quite puzzled by this... I have a line of code that is supposed to > > strip a variable of any non-alphanumeric characters (such as > > whitespace): > > > in my python shell, this works fine: > > >>>key4cache = '!yahoo' > > >>>re.sub(r"[^A-Za-z0-9]", "",key4cache) > > 'yahoo' > > > in django, however: > > logger.debug('key4cache b4:' + key4cache) > > re.sub(r"[^A-Za-z0-9]", "",str(key4cache)) > > logger.debug('key4cache after:' + key4cache) > > > 2008-05-23 18:22:53,325 DEBUG key4cache b4:!yahoo > > 2008-05-23 18:22:53,324 DEBUG key4cache after:!yahoo > > > no change. > > > any ideas? > > re.sub() returns the new string, but you are not saving/assigning the return > value. > > Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex works in python, not in django
On Fri, May 23, 2008 at 10:36 PM, skunkwerk <[EMAIL PROTECTED]> wrote: > > I'm quite puzzled by this... I have a line of code that is supposed to > strip a variable of any non-alphanumeric characters (such as > whitespace): > > in my python shell, this works fine: > >>>key4cache = '!yahoo' > >>>re.sub(r"[^A-Za-z0-9]", "",key4cache) > 'yahoo' > > in django, however: > logger.debug('key4cache b4:' + key4cache) > re.sub(r"[^A-Za-z0-9]", "",str(key4cache)) > logger.debug('key4cache after:' + key4cache) > > 2008-05-23 18:22:53,325 DEBUG key4cache b4:!yahoo > 2008-05-23 18:22:53,324 DEBUG key4cache after:!yahoo > > no change. > > any ideas? > re.sub() returns the new string, but you are not saving/assigning the return value. Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex in url
On 7/16/07, james_027 <[EMAIL PROTECTED]> wrote: > Yes I am looking for the explanation of ?P syntax, is this > something related to python's regex or django's own regex. Ned's quick answer below is quite clear, I think, but if you'd like more details from the horse's mouth (as it were), the official Python docs on regular expressions can be found here: http://docs.python.org/lib/re-syntax.html Jacob --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex in url
For a quick answer: (?Pxxx) means: "match xxx, and store it as a value named blah in the result". This lets the regex machinery build a set of name/value pairs suitable for use as arguments to a view function. --Ned. james_027 wrote: > hi kenneth, > > thanks a lot, i think should be looking at official python doc more > than the dive into python. > > cheers, > james > > On Jul 17, 12:47 pm, Kenneth Gonsalves <[EMAIL PROTECTED]> wrote: > >> On 17-Jul-07, at 9:36 AM, james_027 wrote: >> >> >>> Yes I am looking for the explanation of ?P syntax, is this >>> something related to python's regex or django's own regex. >>> >> python >> >> -- >> >> regards >> kghttp://lawgon.livejournal.comhttp://nrcfosshelpline.in/web/ >> > > > > > > > -- Ned Batchelder, http://nedbatchelder.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex in url
hi kenneth, thanks a lot, i think should be looking at official python doc more than the dive into python. cheers, james On Jul 17, 12:47 pm, Kenneth Gonsalves <[EMAIL PROTECTED]> wrote: > On 17-Jul-07, at 9:36 AM, james_027 wrote: > > > Yes I am looking for the explanation of ?P syntax, is this > > something related to python's regex or django's own regex. > > python > > -- > > regards > kghttp://lawgon.livejournal.comhttp://nrcfosshelpline.in/web/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex in url
On 17-Jul-07, at 9:36 AM, james_027 wrote: > Yes I am looking for the explanation of ?P syntax, is this > something related to python's regex or django's own regex. python -- regards kg http://lawgon.livejournal.com http://nrcfosshelpline.in/web/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex in url
Yes I am looking for the explanation of ?P syntax, is this something related to python's regex or django's own regex. thanks james On Jul 17, 11:57 am, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > On 7/17/07, james_027 <[EMAIL PROTECTED]> wrote: > > > I am very new to django as well as python. how is it that ?P > > seems to be ignore by the regex function? I can't see any explanation > > in django's documentation. is this something magic or hack my django? > > What do you mean by ignored? Are you getting some unexpected > behaviour, or are you looking for an explanation of the ?P > syntax? > > Yours, > Russ Magee %-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex in url
On 7/17/07, james_027 <[EMAIL PROTECTED]> wrote: > I am very new to django as well as python. how is it that ?P > seems to be ignore by the regex function? I can't see any explanation > in django's documentation. is this something magic or hack my django? What do you mean by ignored? Are you getting some unexpected behaviour, or are you looking for an explanation of the ?P syntax? Yours, Russ Magee %-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex
On Feb 13, 11:13 am, "Jeremy Dunck" <[EMAIL PROTECTED]> wrote: > On 2/13/07, kbochert <[EMAIL PROTECTED]> wrote: > > > Given the urlhttp://127.0.0.1:8000/mysite.news.htm > > > then in urls.py > > > (r'^polls/(?P[a-z.]+)', 'Mysite.polls.views.news'), > > #displays page properly, but without the graphics > > ... > I don't think so, unless something odd is going on. How does > mysite.news.htm match something starting with "polls" ? > Ooops brain typo The url is http://127.0.0.1:8000/polls/news.html > ... > > > How can rendering find the correct .gif file and then display it , > > but incorrectly?? > > What's the finished HTML for the img src look like? Django doesn't > know about your web browser. :) The news.html banner is displayed with: The browser is FF 2.0, (IE 6 misdisplays also but a little differently) The OS is Windows 2000 The top half of the banner is displayed in reduced resolution. Other graphics are either similar or missing altogether. I think IE also displays graphics in reduced resolution but but showing alternate stripes rather than fuzzy pixels. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Regex
On 2/13/07, kbochert <[EMAIL PROTECTED]> wrote: > > > Given the url http://127.0.0.1:8000/mysite.news.htm > > then in urls.py > > (r'^polls/(?P[a-z.]+)', 'Mysite.polls.views.news'), > #displays page properly, but without the graphics ... I don't think so, unless something odd is going on. How does mysite.news.htm match something starting with "polls" ? ... > How can rendering find the correct .gif file and then display it , > but incorrectly?? What's the finished HTML for the img src look like? Django doesn't know about your web browser. :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: regex: how to do this in one line of code?
James Bennett wrote: > The fact that you've got three different regular expressions with > three different substitutions to do means that this needs to be three > logical operations. However, you can make this slightly easier on > yourself by building a dictionary of the patterns and substitutions, > then looping over it to do all the heavy lifting. For example: That's pretty cool! Big thanks to James! Regards, - Eric --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: regex: how to do this in one line of code?
On 7/2/06, nkeric <[EMAIL PROTECTED]> wrote: > I'm quite a newbie to regex, could the above code be done in a single > line of regex replacing? The fact that you've got three different regular expressions with three different substitutions to do means that this needs to be three logical operations. However, you can make this slightly easier on yourself by building a dictionary of the patterns and substitutions, then looping over it to do all the heavy lifting. For example: sub_dict = { '[\s]+': ' ', '[-]+': '-', '[.]+': '.' } for pat, sub in sub_dict.iteritems(): decoded_string = re.sub(pat, sub, decoded_string) This also has the advantage of making it easy to add new substitutions later if you find you need them. -- "May the forces of evil become confused on the way to your house." -- George Carlin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---