Giter Site home page Giter Site logo

Comments (8)

dcwatson avatar dcwatson commented on August 22, 2024

Thanks for the suggestions. It seems most of them could be done by just implementing your own [url] renderer that calls the same linker function you provide, and does whatever domain matching and http/https replacement you want. Not that adding customization hooks into the default renderer is a bad idea.

I think passing the context to a linker function is a good idea, but will need to think about backwards compatibility at this point. Trying to call self.linker(url, context) will break existing linkers that just take the url (and no args/*kwargs).

As for performance, I haven't done any serious benchmarking. Are you experiencing performance problems, or do you have any numbers that indicate your suggestions would be an improvement? For my own usage patterns, shaving a few microseconds off a regular expression match won't matter, but I'd be happy to accept patches that are demonstrably faster and pass the tests.

from bbcode.

pythonesque avatar pythonesque commented on August 22, 2024

Yeah, most of those suggestions are just convenience things, no big deal not to add them :)

As far as context goes, I understand where backwards compatibility would be a concern. I was hoping that since it was relatively undocumented (at least, it's not explicitly described on readthedocs, even though it's commented in the source code) that the interface wasn't stable yet. I just really can't think of any other (thread-safe) way to actually pass in context :( Creating a v2 linker or doing some sort of introspection just seems ugly. Maybe make it a module-level option whether context gets passed in or not, a la the thread safe extensions to yacc?

I'll try benchmarking and see what I come up with. Based on the limited tests I've run your module is already pretty optimized, so it may not make much of a difference.

from bbcode.

dcwatson avatar dcwatson commented on August 22, 2024

I'm wondering if some simple introspection would be that bad. Something like:

if linker.func_code.co_argcount == 2 or linker.func_code.co_flags & 4 != 0: linker(url, context)
elif linker.func_code.co_flags & 8 != 0: linker(url, **context)
else: linker(url)

from bbcode.

dcwatson avatar dcwatson commented on August 22, 2024

Also, is there a reason you can't get around this by doing something like:

def linker(url, context=None):
    ...
parser = bbcode.Parser(linker=functools.partial(linker, context=whatever))

from bbcode.

pythonesque avatar pythonesque commented on August 22, 2024

I'll answer your second question first: I can't do that, because the context is different each time I parse (I'm using information from the request header in Django).

First question, your call. I'm generally not a fan of reflection, but it's your project :)

from bbcode.

dcwatson avatar dcwatson commented on August 22, 2024

This is merged. I'm working on a release, should have something soon-ish. Thanks for the feedback and pull request!

from bbcode.

dcwatson avatar dcwatson commented on August 22, 2024

FYI, I just pushed out version 1.0.16 to PyPI (and added some docs on this and other things at http://bbcode.readthedocs.org/en/latest/). Sorry for the delay, and thanks for the contribution!

from bbcode.

pythonesque avatar pythonesque commented on August 22, 2024

Awesome, thanks!
On May 5, 2014 7:10 PM, "Dan Watson" [email protected] wrote:

FYI, I just pushed out version 1.0.16 to PyPI (and added some docs on this
and other things at http://bbcode.readthedocs.org/en/latest/). Sorry for
the delay, and thanks for the contribution!


Reply to this email directly or view it on GitHubhttps://github.com//issues/11#issuecomment-42261032
.

from bbcode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.