File: _web_example1.py

package info (click to toggle)
nodebox-web 1.9.2-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,724 kB
  • ctags: 1,254
  • sloc: python: 6,161; sh: 602; xml: 239; makefile: 33
file content (30 lines) | stat: -rw-r--r-- 879 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Working with URL's.

try:
    # This is the statement you normally use.
    # You can also do "import web" outside of NodeBox.
    web = ximport("web")
except:
    # But since these examples are "inside" the library
    # we may need to try something different when
    # the library is not located in /Application Support
    web = ximport("__init__")
    reload(web)

# Is this a valid URL?
print web.is_url("http://nodebox.net")

# Does the page exist?
print web.url.not_found("http://nodebox.net/nothing")

# Split the URL into different components.
url = web.url.parse("http://nodebox.net/code/index.php/Home")
print "domain:", url.domain
print "page:", url.page

# Retrieve data from the web.
url = "http://nodebox.net/code/data/media/header.jpg"
print web.url.is_image(url)
img = web.url.retrieve(url)
print "download errors:", img.error
image(None, 0, 0, data=img.data)