Internet
This presentation is the property of its rightful owner.
Sponsored Links
1 / 28

Поддержка протоколов Internet PowerPoint PPT Presentation


  • 81 Views
  • Uploaded on
  • Presentation posted in: General

Поддержка протоколов Internet. c gi - протокол CGI используемый для интерпретации форм HTML на стороне сервера. FastCGI - протокол взаимодействия вебсервера и приложения, дальнейшее развитие технологии  CGI . u rllib - чтение произвольных ресурсов по URL. u rlparse - операции над URL.

Download Presentation

Поддержка протоколов Internet

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Internet

Internet

cgi - CGI HTML .

FastCGI - , CGI.

urllib - URL.

urlparse - URL.


C gi cgi

cgi - CGI

  • CGI- HTTP-, . HTTP- , .


Internet

  • HTTP - . -. HTTP URL.


Internet

HTTP :

  • ( ).

  • ( ).

  • .


Tcp ip

TCP/IP

  • TCP/IP , . .

  • TCP/IP:

    • (HTTP)

    • (TCP)

    • (IP)


Http get post

HTTP : GET POST

  • GET URL:http://www.komtet.ru/script.php?login=admin&name=komtet

  • POST , :http://www.komtet.ru/script.php


Internet

CGI- , . , , .

  • #

  • print"Content-Type: text/html"# HTML

  • print# :

  • # HTML

  • print"<html>"

  • print"<title> CGI-</title>"

  • print"<body>"

  • print"<h1> CGI-</h1>"

  • print" !"

  • print"</body>"

  • print"</html>"


Internet

CGI .

  • CGI :

    • URL http://_?_1=_1&_2=2...

    • HTML .


Internet

cgi:

  • import cgi

    # :

  • import cgitb; cgitb.enable()

    # log :

  • import cgitb; cgitb.enable(display=0, logdir="/tmp")


Internet

log-:

  • Logfile - log-.

  • Logfp - , log-.

  • log() - log-


Internet

  • FieldStorage - . .

  • FieldStorage :

  • form = cgi.FieldStorage(keep_blank_values=true)


Cgi name addr

CGI-, , name addr:

  • import cgi

  • print"""\

  • Content-Type: text/html

  • <html>

  • <body>"""

  • form = cgi.FieldStorage()

  • if form.has_key("name")and form.has_key("addr"):

  • print """\

  • <p>eIN: %s</p>

  • <p>aAOAO: %s</p>"""

  • else:

  • print"""\

  • <h1></h1>

  • <p>, , .</p>"""

  • print"""\

  • </body>

  • </html>"""


Internet

, type() :

  • value = form.getvalue("username", "")

  • if type(value) is type([]):

  • #

  • usernames = ",".join(value)

  • else:

  • #

  • usernames = value


Internet

, value . , , filename file:

  • fileitem = form["userfile"]

  • if fileitem.file:

  • # fileitem .

  • # , .

  • linecount = 0

  • while 1:

  • if fileitem.file.readline():

  • linecount += 1

  • else:

  • break


Internet

cgi

  • test() - CGI-, : HTTP- HTML.


Fastcgi

FastCGI

  • CGI .

  • FastCGI CGI-. CGI- , - , .

  • FastCGI , . .


Internet

urllib

URL


Read readline readlines fileno close

, , read(), readline(), readlines(), fileno() close() :

  • info() - HTTP .

  • geturl() - URL .


Internet

  • urlopen() urlretrieve() FancyURLopener. . , :

    • URLopener() - , .

    • FancyURLopener() - HTTP-


Internet

  • import urllib

  • class AppURLopener(urllib.FancyURLopener):

  • version = "App/1.7"

  • urllib._urlopener = AppURLopener()


Get http

GET HTTP:

  • import urllib

  • params = urllib.urlencode({'spam': 1, \ 'eggs': 2, \

    'bacon': 0})

  • f = urllib.urlopen("http://www.musi-cal.com/cgi-bin/query?%s" % params)

  • print f.read()


Internet

, POST:

  • import urllib

  • params = urllib.urlencode({'spam': 1, \

  • 'eggs': 2, \

  • 'bacon': 0})

  • f = urllib.urlopen("http://www.musi-cal.com/cgi-bin/query", params)

  • print f.read()


Internet

  • import urllib

  • params = urllib.urlencode({'text': 'elephant and giraf'})

  • print params

  • f = urllib.urlopen("http://yandex.ru/yandsearch?" + params)

  • print f.geturl()

    #text=elephant+and+giraf

    #http://yandex.ru/yandsearch?text=elephant+and+giraf&lr=2

  • print f.read() #


Urlparse url

urlparse URL

  • URL , URL URL .


Internet

  • urlparse() - : , , , , .

  • : scheme://netloc/path;parameters?query#fragment :

    (scheme, netloc, path, parameters, query, fragment).


Internet

>>> import urlparse

>>> urlparse.urlparse(

... 'http://www.cwi.nl:80/%7Eguido/Python.html')

ParseResult(scheme='http', netloc='www.cwi.nl:80', path='/%7Eguido/Python.html', params='', query='', fragment='')


Internet

  • urlunparse() - URL , .

  • urljoin() URL, URL URL


Internet

import urlparse

urlparse.urljoin('http://www.cwi.nl/%7Eguido/

Python.html','FAQ.html')

'http://www.cwi.nl/%7Eguido/FAQ.html'


  • Login