Mailing List Archive

Problem with `search`
Folks,

I am writing a plugin for internal use that access some internal data and I wanted to provide a `search` sub-page for that data.

So I rolled my own `\plugin\search\` url handler and it doesn't (always) work. On my dev setup my search has replaced the standard search and in the release environment the standard search appears instead.

Trac 0.12.3 (and current trunk at t.e.o) search uses the following:
{{{
def match_request(self, req):
return re.match(r'/search(?:/opensearch)?$', req.path_info) is not None
}}}

...which matches search at the end of any URL.

I can fix this by using a different word (`research` springs to mind) but this could affect other users.

Would this regex not work better: r'^/search(?:/opensearch)?$' as my understanding of req.path_info is that the main URL is removed before being passed in req?

Can anyone confirm (or deny) my understanding? Should I raise a ticket?

Regards,

~ Mark C

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To post to this group, send email to trac-users@googlegroups.com.
To unsubscribe from this group, send email to trac-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/trac-users?hl=en.
RE: Problem with `search` [ In reply to ]
Cooke, Mark wrote (Wednesday, August 08, 2012 10:29 AM):

> I am writing a plugin for internal use that access some internal
> data and I wanted to provide a `search` sub-page for that data.
>
> So I rolled my own `\plugin\search\` url handler and it doesn't
> (always) work. On my dev setup my search has replaced the standard
> search and in the release environment the standard search appears instead.
>
> Trac 0.12.3 (and current trunk at t.e.o) search uses the following:
> {{{
> def match_request(self, req):
> return re.match(r'/search(?:/opensearch)?$', req.path_info) is not None
> }}}
>
>...which matches search at the end of any URL.
>
> I can fix this by using a different word (`research`
> springs to mind) but this could affect other users.
>
> Would this regex not work better: r'^/search(?:/opensearch)?$'
> as my understanding of req.path_info is that the main URL is
> removed before being passed in req?
>
> Can anyone confirm (or deny) my understanding? Should I raise a ticket?

Hi Mark,

the approach seems to be okay (although I didn't try it).
I personally wouldn't change the regex, moreover I'd have apache
do some URL rewriting ... so your plugin doesn't need to be named
"search" (at least visible to the user).

Have a nice day,
Berny

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To post to this group, send email to trac-users@googlegroups.com.
To unsubscribe from this group, send email to trac-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/trac-users?hl=en.
Re: Problem with `search` [ In reply to ]
> Trac 0.12.3 (and current trunk at t.e.o) search uses the following:
> {{{
> def match_request(self, req):
> return re.match(r'/search(?:/opensearch)?$', req.path_info) is not None
> }}}
>
> ...which matches search at the end of any URL.

No, re.match() matches at the beginning of the string. re.search()
matches anywhere in the string.

$ python
Python 2.7.3 (default, Jun 18 2012, 20:21:41)
[GCC 4.5.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> re.match(r'/search(?:/opensearch)?$', '/search')
<_sre.SRE_Match object at 0xb76a8020>
>>> re.match(r'/search(?:/opensearch)?$', '/search/opensearch')
<_sre.SRE_Match object at 0xb76a8170>
>>> re.match(r'/search(?:/opensearch)?$', '/search/something')
>>> re.match(r'/search(?:/opensearch)?$', '/my/search')
>>> re.search(r'/search(?:/opensearch)?$', '/my/search')
<_sre.SRE_Match object at 0xb76a8020>

-- Remy
RE: Problem with `search` [ In reply to ]
> -----Original Message-----
> From: trac-users@googlegroups.com On Behalf Of Remy Blank
> Sent: 08 August 2012 10:01
> To: trac-users@googlegroups.com
> Subject: Re: [Trac] Problem with `search`
>
> > Trac 0.12.3 (and current trunk at t.e.o) search uses the following:
> > {{{
> > def match_request(self, req):
> > return re.match(r'/search(?:/opensearch)?$',
> req.path_info) is not None
> > }}}
> >
> > ...which matches search at the end of any URL.
>
> No, re.match() matches at the beginning of the string. re.search()
> matches anywhere in the string.
>
> $ python
> Python 2.7.3 (default, Jun 18 2012, 20:21:41)
> [GCC 4.5.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import re
> >>> re.match(r'/search(?:/opensearch)?$', '/search')
> <_sre.SRE_Match object at 0xb76a8020>
> >>> re.match(r'/search(?:/opensearch)?$', '/search/opensearch')
> <_sre.SRE_Match object at 0xb76a8170>
> >>> re.match(r'/search(?:/opensearch)?$', '/search/something')
> >>> re.match(r'/search(?:/opensearch)?$', '/my/search')
> >>> re.search(r'/search(?:/opensearch)?$', '/my/search')
> <_sre.SRE_Match object at 0xb76a8020>

Thanks Remy,

I have since discovered that the problem is probably with the name of my template: "search.html". Even though it is stored in my plugin folder it gets found before/after the trac one (I've not worked out the priority).

Anyway, is there a way to add a path to a html template (like get_htdocs_dirs() allows) or must a plugin's html templates use unique names?

~ mark c


--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To post to this group, send email to trac-users@googlegroups.com.
To unsubscribe from this group, send email to trac-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/trac-users?hl=en.
Re: Problem with `search` [ In reply to ]
Cooke, Mark wrote:
> I have since discovered that the problem is probably with the name of my template: "search.html". Even though it is stored in my plugin folder it gets found before/after the trac one (I've not worked out the priority).
>
> Anyway, is there a way to add a path to a html template (like get_htdocs_dirs() allows) or must a plugin's html templates use unique names?

I don't think you can, so you'll need to have a unique name. I usually
name my templates e.g. "{plugin_name}_search.html".

-- Remy
RE: Problem with `search` [ In reply to ]
> -----Original Message-----
> From: trac-users@googlegroups.com On Behalf Of Remy Blank
> Sent: 08 August 2012 12:11
> To: trac-users@googlegroups.com
> Subject: Re: [Trac] Problem with `search`
>
> Cooke, Mark wrote:
> > I have since discovered that the problem is probably with
> the name of my template: "search.html". Even though it is
> stored in my plugin folder it gets found before/after the
> trac one (I've not worked out the priority).
> >
> > Anyway, is there a way to add a path to a html template
> (like get_htdocs_dirs() allows) or must a plugin's html
> templates use unique names?
>
> I don't think you can, so you'll need to have a unique name. I usually
> name my templates e.g. "{plugin_name}_search.html".
>
> -- Remy

Thanks again Remy. I've renamed my template and all seems good.

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To post to this group, send email to trac-users@googlegroups.com.
To unsubscribe from this group, send email to trac-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/trac-users?hl=en.
Re: Problem with `search` [ In reply to ]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am 08.08.2012 13:10, schrieb Remy Blank:
> I don't think you can, so you'll need to have a unique name. I usually
> name my templates e.g. "{plugin_name}_search.html".

Yes, you need unique names. This is what I experienced recently too.

Steffen Hoffmann
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlAi2QMACgkQ31DJeiZFuHcocgCdHspdfV8v6wF9ZNdzHA7WDevj
kQ0An2hol+HbY4pOJCg0fvhglBXq6FyB
=f8C3
-----END PGP SIGNATURE-----

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To post to this group, send email to trac-users@googlegroups.com.
To unsubscribe from this group, send email to trac-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/trac-users?hl=en.