Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8291231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:03:24+00:00 2026-06-08T13:03:24+00:00

In WeasyPrint’s public API I accept either filenames or URLs (among other types) for

  • 0

In WeasyPrint’s public API I accept either filenames or URLs (among other types) for the HTML input:

document = HTML(filename='/foo/bar/baz.html')
document = HTML(url='http://example.net/bar/baz.html')

There is also the option not to name the argument and let WeasyPrint guess its type:

document = HTML(sys.argv[1])

Some cases are easy: if it starts with a / on Unix it’s a filename, if it starts with http:// it’s probably an URL. But we need an general algorithm that gives an answer for any string.

Currently I try to match this regexp: ^([a-z][a-z0-1.+-]*):. A string that matches starts with a valid URI scheme according to RFC 3986 (URI). This is not bad on Unix, but utterly fails on Windows: C:\foo\bar.html matches and is treated like an URL.

I could change the * to + in the regexp and only match URI schemes that are at least two characters long. Apparently there is no known URI scheme shorter than that.

Or is there a better criteria? Maybe I should just restrict "guessed" URLs to a handful of schemes. More exotic cases can still use HTML(url=foo).

url.startswith(['http:', 'https:', 'ftp:', 'data:'])
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T13:03:30+00:00Added an answer on June 8, 2026 at 1:03 pm

    If you really must guess well between filenames and URLs, I’d say a string with 2 or more word characters and then a colon was a URL, anything else is a file, just as you suggest.

    Another option: try to open it as a file. If it fails, try to open it as a URL.

    Better might be to listen to the Zen of Python, “resist the temptation to guess”. Doesn’t the caller know if he’s talking about a filename or a URL? Have them specify it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get EasyPrint to work from workstations running Windows Server 2003, connecting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.