SlideShare une entreprise Scribd logo
1  sur  33
Télécharger pour lire hors ligne
●   Tornado, Friendfeed'in kullandığı non-blocking
    (bkz:non blocking) ve ölçeklenebilir web
    araçlarının adıdır.

●   Facebook, Friendfeed'i satın aldıktan Apache
    lisansı ile açık kaynak olarak dağıtılmaya
    başlandı.
| Kurulum
wget -c http://github.com/downloads/facebook/tornado/tornado-1.0.tar.gz
tar xvzf tornado-1.0.tar.gz
cd tornado-1.0
python setup.py build
sudo python setup.py install


Veya


apt-get install pyton-tornado (debian sid)
| Performans
●   'Hello world' performansı
| Modüller
           High Level Modüller                 Low level modüller
●   web                           ●   httpserver
●   escape                        ●   iostream
●   database                      ●   İoloop
●   template
●   httpclient
●   auth
●   locale                        ●   epoll
●   options
| web
Friendfeed'in üzerine kurulduğu, başlıca ana
           parçaları içeren modül
| escape
XHTML, JSON ve URL encode/decode işlemleri
              için modüller
| database
MySQLdb modülü üzerine geliştirilmiş bir wrapper
| template
Şablon motoru
| auth
         3. parti kimlik doğrulama kütüphaneleri
(Google OpenID/OAuth, Facebook Platform, Yahoo BBAuth,
        FriendFeed OpenID/OAuth, Twitter OAuth)
| locale
Yerelleştirme desteği için modül
| options
Komut satırından veya yapılandırma dosyasından
   yapılandırma almak için modül (optparser)
| low level
Bunların altında ise esas non-blocking işlemleri yapan
●   httpserver : non-blocking http sunucu
●   iostream : non-blocking socketleri okumak için geliştirilmiş bir modül
●   ioloop : ana i/o modülü




●   Bir de amazon s3 simüle eden bir sunucu modülü var.
| kod örnekleri

http://github.com/yuxel/snippets/tree/master/python/tornado/
#!/usr/bin/python
                                                                | hello world
import tornado.httpserver
import tornado.ioloop
import tornado.web


class HelloHandler(tornado.web.RequestHandler):
     def get(self):
       self.write("Hello World")


application = tornado.web.Application([
     (r"/", HelloHandler),
])


if __name__ == "__main__":
     http_server = tornado.httpserver.HTTPServer(application)
     http_server.listen(8888)
     tornado.ioloop.IOLoop.instance().start()



             http://github.com/yuxel/snippets/blob/master/python/tornado/helloWorld.py
.....
                                              | request handling
# handles pages matches URI /another/someUriParam
class AnotherHandler(tornado.web.RequestHandler):
     def get(self,uriParam):
         self.write("This is another page with URI parameter = " + uriParam)


application = tornado.web.Application([
     (r"/another/([^/]+)", AnotherHandler),
])


....


        http://github.com/yuxel/snippets/blob/master/python/tornado/requestHandling.py
...
                                                                | request handling
# handles pages matches /postTest/ and demonstrate getting request parameter
class PostSomethingHandler(tornado.web.RequestHandler):
      def get(self):
        form = """<form method="post">
        <input type="text" name="something"/>
        <input type="submit"/>
        </form>"""
        self.write(form)


      def post(self):
        postedValue = self.get_argument("something") # get request argument
        self.write("You've postted 'something' as : " + postedValue)



application = tornado.web.Application([
      (r"/postTest/", PostSomethingHandler),
])
...


         http://github.com/yuxel/snippets/blob/master/python/tornado/requestHandling.py
...
                                            | request handling
# demonstrates an HTTP response error
class ResponseErrorHandler(tornado.web.RequestHandler):
      def get(self):
        # send a 403 forbidden error
        raise tornado.web.HTTPError(403)



application = tornado.web.Application([
      (r"/someError/", ResponseErrorHandler),
])


...


       http://github.com/yuxel/snippets/blob/master/python/tornado/requestHandling.py
...
                                                         | cookie
# demonstrates cookie usage
class MainHandler(tornado.web.RequestHandler):
      def get(self):
        cookieName = "pyist";
        cookieValue = self.get_cookie(cookieName)
        currentTimestamp = str(time.time())
        if not cookieValue:
           self.set_cookie(cookieName, currentTimestamp)
           self.write("I've just set your cookie, refresh!")
        else:
           self.write("Cookie value : " + cookieValue)



...



                http://github.com/yuxel/snippets/blob/master/python/tornado/cookie.py
...
                                                         | secure cookie
# demonstrates secure cookie example
class SecureCookieHandler(tornado.web.RequestHandler):
      def get(self):
        cookieName = "pyist_secure";
        cookieValue = self.get_secure_cookie(cookieName)
        currentTimestamp = str(time.time())
        if not cookieValue:
           self.set_secure_cookie(cookieName, currentTimestamp)
           self.write("I've just set your cookie, refresh!")
        else:
           self.write("Cookie value : " + cookieValue)



...



                http://github.com/yuxel/snippets/blob/master/python/tornado/cookie.py
...
<!DOCTYPE html>
                                                 | template
<html>
      <head>
        <title>{{ title }}</title>
        <meta charset="utf-8" />
      </head>
      <body>
        {% if userLogged %}
           Hi {{ userLogged }}
        {% else %}
           You need to log in to see this page
        {% end %}
      </body>
</html>




...



        http://github.com/yuxel/snippets/blob/master/python/tornado/templates/main.html
...
                                                | template
# handles main page
class MainHandler(tornado.web.RequestHandler):
      def get(self):
        #we demonstrate this using a ?userLogged=userName parameter
        switchLoggedFromGet = self.get_argument("userLogged", False)


        #remove html entities
        switchLoggedFromGet = tornado.escape.xhtml_escape(switchLoggedFromGet)


        self.render("templates/main.html", title="Pyist.net", userLogged=switchLoggedFromGet)



...


            http://github.com/yuxel/snippets/blob/master/python/tornado/template.py
...
                                                           | locale
class TRHandler(tornado.web.RequestHandler):
      def get(self):
        tornado.locale.set_default_locale('tr_TR')
        self.render("templates/translation.html")


# English page
class ENHandler(tornado.web.RequestHandler):
      def get(self):
        tornado.locale.set_default_locale('en_US')
        self.render("templates/translation.html")
...
if __name__ == "__main__":
      #set path for location dir
      translationsPath = os.path.join(os.path.dirname(__file__), "translations")
      tornado.locale.load_translations(translationsPath)
...

            http://github.com/yuxel/snippets/blob/master/python/tornado/translation.py
tr_TR.csv
                                      | locale
"Hello World!","Merhaba dunya!"
"This is another test","Bu bir test"



en_EN.csv
"Hello World!","Hello, world!"
"This is another test","This is another test"

     http://github.com/yuxel/snippets/blob/master/python/tornado/translations
...
                                                    | xsrf koruması
# handles main page
class MainHandler(tornado.web.RequestHandler):
      def get(self):
        self.render("templates/xsrf.html")


      # if _xsrf value doesnt match xsrf cookie value, this will return 403
      def post(self):
        postedValue = self.get_argument("something") # get request argument
        self.write("You've postted 'something' as : " + postedValue)


application = tornado.web.Application([
      (r"/", MainHandler),
], cookie_secret="SomeSecret",xsrf_cookies=True)
...

               http://github.com/yuxel/snippets/blob/master/python/tornado/xsrf.py
| xsrf koruması
<!DOCTYPE html>
<html>
  <head>
    <title>Pyist Tornadoweb</title>
    <meta charset="utf-8" />
  </head>
  <body>
    <form action="" method="post">
     {{ xsrf_form_html() }}
     <div>
         Write something: <input type="text" name="something"/>
         <input type="submit" value="Try"/>
     </div>
    </form>
  </body>
</html>

    http://github.com/yuxel/snippets/blob/master/python/tornado/templates/xsrf.html
import tornado.httpclient
                                                             | asenkron istekler
...
class MainHandler(tornado.web.RequestHandler):
      @tornado.web.asynchronous
      def get(self):
        http = tornado.httpclient.AsyncHTTPClient()
        url = "http://api.eksigator.com/demo/demo/getList"
        http.fetch(url, callback=self.async_callback(self.on_response))


      def on_response(self, response):
        items = tornado.escape.json_decode(response.body)
        for item in items:
           self.write( item["title"] + "<br/>" )


        # this will end async requst
        self.finish()
...

                http://github.com/yuxel/snippets/blob/master/python/tornado/async.py
| database
import tornado.database
...


class DBHandler(tornado.web.RequestHandler):
      def get(self):
        db = tornado.database.Connection(
           host="localhost", database="pyist",
           user="root", password="12345678")


        datas = db.query("select name_surname from pyist")


        # print datas
        for data in datas:
           self.write(data["name_surname"])
           self.write("<br/>")
...

             http://github.com/yuxel/snippets/blob/master/python/tornado/database.py
...
                                           | static dosyalar
application = tornado.web.Application([
      (r"/", MainHandler),
], static_path = os.path.join(os.path.dirname(__file__), "static"))


...



{{ static_url(“hello.txt”) }}
         http://github.com/yuxel/snippets/blob/master/python/tornado/translation.py
| chat demo
 Chat demosunu sadeleştirilmiş hali




http://github.com/yuxel/snippets/blob/master/python/tornado/chat/
| proje

http://github.com/yuxel/feedget
  http://feedget.net/ (alpha)
| kaynaklar

   http://www.tornadoweb.org/
http://github.com/facebook/tornado
   irc://irc.freenode.net/tornado
| iletişim
      Osman Yüksel

yuxel |ET| sonsuzdongu {DAT} com
         http://yuxel.net

Contenu connexe

Tendances

服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScriptQiangning Hong
 
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiGrâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiJérémy Derussé
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterZendCon
 
wwc start-launched
wwc start-launchedwwc start-launched
wwc start-launchedMat Schaffer
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsSolution4Future
 
Multithreading on iOS
Multithreading on iOSMultithreading on iOS
Multithreading on iOSMake School
 
Php on the desktop and php gtk2
Php on the desktop and php gtk2Php on the desktop and php gtk2
Php on the desktop and php gtk2Elizabeth Smith
 
A million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleA million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleTom Croucher
 
Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013Charles Nutter
 
MFF UK - Advanced iOS Topics
MFF UK - Advanced iOS TopicsMFF UK - Advanced iOS Topics
MFF UK - Advanced iOS TopicsPetr Dvorak
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOSPetr Dvorak
 
Customising Your Own Web Framework In Go
Customising Your Own Web Framework In GoCustomising Your Own Web Framework In Go
Customising Your Own Web Framework In GoJonathan Gomez
 
JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011Charles Nutter
 
Building servers with Node.js
Building servers with Node.jsBuilding servers with Node.js
Building servers with Node.jsConFoo
 
Apache ant
Apache antApache ant
Apache antkoniik
 
Aura Project for PHP
Aura Project for PHPAura Project for PHP
Aura Project for PHPHari K T
 

Tendances (20)

Python, do you even async?
Python, do you even async?Python, do you even async?
Python, do you even async?
 
服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript
 
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiGrâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
 
Pycon - Python for ethical hackers
Pycon - Python for ethical hackers Pycon - Python for ethical hackers
Pycon - Python for ethical hackers
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life better
 
wwc start-launched
wwc start-launchedwwc start-launched
wwc start-launched
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutions
 
Multithreading on iOS
Multithreading on iOSMultithreading on iOS
Multithreading on iOS
 
Php on the desktop and php gtk2
Php on the desktop and php gtk2Php on the desktop and php gtk2
Php on the desktop and php gtk2
 
A million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleA million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scale
 
Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013
 
MFF UK - Advanced iOS Topics
MFF UK - Advanced iOS TopicsMFF UK - Advanced iOS Topics
MFF UK - Advanced iOS Topics
 
Php go vrooom!
Php go vrooom!Php go vrooom!
Php go vrooom!
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOS
 
Customising Your Own Web Framework In Go
Customising Your Own Web Framework In GoCustomising Your Own Web Framework In Go
Customising Your Own Web Framework In Go
 
JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011
 
Tatsumaki
TatsumakiTatsumaki
Tatsumaki
 
Building servers with Node.js
Building servers with Node.jsBuilding servers with Node.js
Building servers with Node.js
 
Apache ant
Apache antApache ant
Apache ant
 
Aura Project for PHP
Aura Project for PHPAura Project for PHP
Aura Project for PHP
 

En vedette

An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to TornadoGavin Roy
 
Introduction to Tornado - TienNA
Introduction to Tornado - TienNAIntroduction to Tornado - TienNA
Introduction to Tornado - TienNAFramgia Vietnam
 
Özgür Web Günleri 2013 | Python + Tornado + Nginx + Mongodb ile Ölçeklenebili...
Özgür Web Günleri 2013 | Python + Tornado + Nginx + Mongodb ile Ölçeklenebili...Özgür Web Günleri 2013 | Python + Tornado + Nginx + Mongodb ile Ölçeklenebili...
Özgür Web Günleri 2013 | Python + Tornado + Nginx + Mongodb ile Ölçeklenebili...Mehmet Köse
 
Real time server
Real time serverReal time server
Real time serverthepian
 
What is a tornado?
What is a tornado?What is a tornado?
What is a tornado?Austin
 
Contoh Lembar Catatan Fakta Guru
Contoh Lembar Catatan Fakta GuruContoh Lembar Catatan Fakta Guru
Contoh Lembar Catatan Fakta Guruenesha sie
 
Web backends development using Python
Web backends development using PythonWeb backends development using Python
Web backends development using PythonAyun Park
 

En vedette (9)

An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
 
Tornado
TornadoTornado
Tornado
 
Tornado
TornadoTornado
Tornado
 
Introduction to Tornado - TienNA
Introduction to Tornado - TienNAIntroduction to Tornado - TienNA
Introduction to Tornado - TienNA
 
Özgür Web Günleri 2013 | Python + Tornado + Nginx + Mongodb ile Ölçeklenebili...
Özgür Web Günleri 2013 | Python + Tornado + Nginx + Mongodb ile Ölçeklenebili...Özgür Web Günleri 2013 | Python + Tornado + Nginx + Mongodb ile Ölçeklenebili...
Özgür Web Günleri 2013 | Python + Tornado + Nginx + Mongodb ile Ölçeklenebili...
 
Real time server
Real time serverReal time server
Real time server
 
What is a tornado?
What is a tornado?What is a tornado?
What is a tornado?
 
Contoh Lembar Catatan Fakta Guru
Contoh Lembar Catatan Fakta GuruContoh Lembar Catatan Fakta Guru
Contoh Lembar Catatan Fakta Guru
 
Web backends development using Python
Web backends development using PythonWeb backends development using Python
Web backends development using Python
 

Similaire à Tornadoweb

GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineYared Ayalew
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Hugo Hamon
 
Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPTwig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPFabien Potencier
 
Web Crawling with NodeJS
Web Crawling with NodeJSWeb Crawling with NodeJS
Web Crawling with NodeJSSylvain Zimmer
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for JoomlaLuke Summerfield
 
Flask intro - ROSEdu web workshops
Flask intro - ROSEdu web workshopsFlask intro - ROSEdu web workshops
Flask intro - ROSEdu web workshopsAlex Eftimie
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Djangofool2nd
 
Hands on django part 1
Hands on django part 1Hands on django part 1
Hands on django part 1MicroPyramid .
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングscalaconfjp
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Ngoc Dao
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareAlona Mekhovova
 
Nginx + Tornado = 17k req/s
Nginx + Tornado = 17k req/sNginx + Tornado = 17k req/s
Nginx + Tornado = 17k req/smoret1979
 
Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)
Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)
Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)Mark Hamstra
 
Drupal vs WordPress
Drupal vs WordPressDrupal vs WordPress
Drupal vs WordPressWalter Ebert
 
Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)
Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)
Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)Mark Hamstra
 

Similaire à Tornadoweb (20)

GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2
 
Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPTwig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHP
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Web Crawling with NodeJS
Web Crawling with NodeJSWeb Crawling with NodeJS
Web Crawling with NodeJS
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
 
Flask intro - ROSEdu web workshops
Flask intro - ROSEdu web workshopsFlask intro - ROSEdu web workshops
Flask intro - ROSEdu web workshops
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
 
Hands on django part 1
Hands on django part 1Hands on django part 1
Hands on django part 1
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
 
Nginx + Tornado = 17k req/s
Nginx + Tornado = 17k req/sNginx + Tornado = 17k req/s
Nginx + Tornado = 17k req/s
 
Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)
Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)
Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)
 
Drupal vs WordPress
Drupal vs WordPressDrupal vs WordPress
Drupal vs WordPress
 
Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)
Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)
Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)
 

Plus de Osman Yuksel

Plus de Osman Yuksel (8)

Jenkins
JenkinsJenkins
Jenkins
 
PHPUnit ve Laravel
PHPUnit ve LaravelPHPUnit ve Laravel
PHPUnit ve Laravel
 
Varnish
VarnishVarnish
Varnish
 
Muhafiz
MuhafizMuhafiz
Muhafiz
 
Selenium
SeleniumSelenium
Selenium
 
Jasminebdd
JasminebddJasminebdd
Jasminebdd
 
Web Onyuzu Nasil Olmali
Web Onyuzu Nasil OlmaliWeb Onyuzu Nasil Olmali
Web Onyuzu Nasil Olmali
 
JavaScript sunumu
JavaScript sunumuJavaScript sunumu
JavaScript sunumu
 

Dernier

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Dernier (20)

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 

Tornadoweb

  • 1.
  • 2. Tornado, Friendfeed'in kullandığı non-blocking (bkz:non blocking) ve ölçeklenebilir web araçlarının adıdır. ● Facebook, Friendfeed'i satın aldıktan Apache lisansı ile açık kaynak olarak dağıtılmaya başlandı.
  • 3. | Kurulum wget -c http://github.com/downloads/facebook/tornado/tornado-1.0.tar.gz tar xvzf tornado-1.0.tar.gz cd tornado-1.0 python setup.py build sudo python setup.py install Veya apt-get install pyton-tornado (debian sid)
  • 4. | Performans ● 'Hello world' performansı
  • 5. | Modüller High Level Modüller Low level modüller ● web ● httpserver ● escape ● iostream ● database ● İoloop ● template ● httpclient ● auth ● locale ● epoll ● options
  • 6. | web Friendfeed'in üzerine kurulduğu, başlıca ana parçaları içeren modül
  • 7. | escape XHTML, JSON ve URL encode/decode işlemleri için modüller
  • 8. | database MySQLdb modülü üzerine geliştirilmiş bir wrapper
  • 10. | auth 3. parti kimlik doğrulama kütüphaneleri (Google OpenID/OAuth, Facebook Platform, Yahoo BBAuth, FriendFeed OpenID/OAuth, Twitter OAuth)
  • 12. | options Komut satırından veya yapılandırma dosyasından yapılandırma almak için modül (optparser)
  • 13. | low level Bunların altında ise esas non-blocking işlemleri yapan ● httpserver : non-blocking http sunucu ● iostream : non-blocking socketleri okumak için geliştirilmiş bir modül ● ioloop : ana i/o modülü ● Bir de amazon s3 simüle eden bir sunucu modülü var.
  • 15. #!/usr/bin/python | hello world import tornado.httpserver import tornado.ioloop import tornado.web class HelloHandler(tornado.web.RequestHandler): def get(self): self.write("Hello World") application = tornado.web.Application([ (r"/", HelloHandler), ]) if __name__ == "__main__": http_server = tornado.httpserver.HTTPServer(application) http_server.listen(8888) tornado.ioloop.IOLoop.instance().start() http://github.com/yuxel/snippets/blob/master/python/tornado/helloWorld.py
  • 16. ..... | request handling # handles pages matches URI /another/someUriParam class AnotherHandler(tornado.web.RequestHandler): def get(self,uriParam): self.write("This is another page with URI parameter = " + uriParam) application = tornado.web.Application([ (r"/another/([^/]+)", AnotherHandler), ]) .... http://github.com/yuxel/snippets/blob/master/python/tornado/requestHandling.py
  • 17. ... | request handling # handles pages matches /postTest/ and demonstrate getting request parameter class PostSomethingHandler(tornado.web.RequestHandler): def get(self): form = """<form method="post"> <input type="text" name="something"/> <input type="submit"/> </form>""" self.write(form) def post(self): postedValue = self.get_argument("something") # get request argument self.write("You've postted 'something' as : " + postedValue) application = tornado.web.Application([ (r"/postTest/", PostSomethingHandler), ]) ... http://github.com/yuxel/snippets/blob/master/python/tornado/requestHandling.py
  • 18. ... | request handling # demonstrates an HTTP response error class ResponseErrorHandler(tornado.web.RequestHandler): def get(self): # send a 403 forbidden error raise tornado.web.HTTPError(403) application = tornado.web.Application([ (r"/someError/", ResponseErrorHandler), ]) ... http://github.com/yuxel/snippets/blob/master/python/tornado/requestHandling.py
  • 19. ... | cookie # demonstrates cookie usage class MainHandler(tornado.web.RequestHandler): def get(self): cookieName = "pyist"; cookieValue = self.get_cookie(cookieName) currentTimestamp = str(time.time()) if not cookieValue: self.set_cookie(cookieName, currentTimestamp) self.write("I've just set your cookie, refresh!") else: self.write("Cookie value : " + cookieValue) ... http://github.com/yuxel/snippets/blob/master/python/tornado/cookie.py
  • 20. ... | secure cookie # demonstrates secure cookie example class SecureCookieHandler(tornado.web.RequestHandler): def get(self): cookieName = "pyist_secure"; cookieValue = self.get_secure_cookie(cookieName) currentTimestamp = str(time.time()) if not cookieValue: self.set_secure_cookie(cookieName, currentTimestamp) self.write("I've just set your cookie, refresh!") else: self.write("Cookie value : " + cookieValue) ... http://github.com/yuxel/snippets/blob/master/python/tornado/cookie.py
  • 21. ... <!DOCTYPE html> | template <html> <head> <title>{{ title }}</title> <meta charset="utf-8" /> </head> <body> {% if userLogged %} Hi {{ userLogged }} {% else %} You need to log in to see this page {% end %} </body> </html> ... http://github.com/yuxel/snippets/blob/master/python/tornado/templates/main.html
  • 22. ... | template # handles main page class MainHandler(tornado.web.RequestHandler): def get(self): #we demonstrate this using a ?userLogged=userName parameter switchLoggedFromGet = self.get_argument("userLogged", False) #remove html entities switchLoggedFromGet = tornado.escape.xhtml_escape(switchLoggedFromGet) self.render("templates/main.html", title="Pyist.net", userLogged=switchLoggedFromGet) ... http://github.com/yuxel/snippets/blob/master/python/tornado/template.py
  • 23. ... | locale class TRHandler(tornado.web.RequestHandler): def get(self): tornado.locale.set_default_locale('tr_TR') self.render("templates/translation.html") # English page class ENHandler(tornado.web.RequestHandler): def get(self): tornado.locale.set_default_locale('en_US') self.render("templates/translation.html") ... if __name__ == "__main__": #set path for location dir translationsPath = os.path.join(os.path.dirname(__file__), "translations") tornado.locale.load_translations(translationsPath) ... http://github.com/yuxel/snippets/blob/master/python/tornado/translation.py
  • 24. tr_TR.csv | locale "Hello World!","Merhaba dunya!" "This is another test","Bu bir test" en_EN.csv "Hello World!","Hello, world!" "This is another test","This is another test" http://github.com/yuxel/snippets/blob/master/python/tornado/translations
  • 25. ... | xsrf koruması # handles main page class MainHandler(tornado.web.RequestHandler): def get(self): self.render("templates/xsrf.html") # if _xsrf value doesnt match xsrf cookie value, this will return 403 def post(self): postedValue = self.get_argument("something") # get request argument self.write("You've postted 'something' as : " + postedValue) application = tornado.web.Application([ (r"/", MainHandler), ], cookie_secret="SomeSecret",xsrf_cookies=True) ... http://github.com/yuxel/snippets/blob/master/python/tornado/xsrf.py
  • 26. | xsrf koruması <!DOCTYPE html> <html> <head> <title>Pyist Tornadoweb</title> <meta charset="utf-8" /> </head> <body> <form action="" method="post"> {{ xsrf_form_html() }} <div> Write something: <input type="text" name="something"/> <input type="submit" value="Try"/> </div> </form> </body> </html> http://github.com/yuxel/snippets/blob/master/python/tornado/templates/xsrf.html
  • 27. import tornado.httpclient | asenkron istekler ... class MainHandler(tornado.web.RequestHandler): @tornado.web.asynchronous def get(self): http = tornado.httpclient.AsyncHTTPClient() url = "http://api.eksigator.com/demo/demo/getList" http.fetch(url, callback=self.async_callback(self.on_response)) def on_response(self, response): items = tornado.escape.json_decode(response.body) for item in items: self.write( item["title"] + "<br/>" ) # this will end async requst self.finish() ... http://github.com/yuxel/snippets/blob/master/python/tornado/async.py
  • 28. | database import tornado.database ... class DBHandler(tornado.web.RequestHandler): def get(self): db = tornado.database.Connection( host="localhost", database="pyist", user="root", password="12345678") datas = db.query("select name_surname from pyist") # print datas for data in datas: self.write(data["name_surname"]) self.write("<br/>") ... http://github.com/yuxel/snippets/blob/master/python/tornado/database.py
  • 29. ... | static dosyalar application = tornado.web.Application([ (r"/", MainHandler), ], static_path = os.path.join(os.path.dirname(__file__), "static")) ... {{ static_url(“hello.txt”) }} http://github.com/yuxel/snippets/blob/master/python/tornado/translation.py
  • 30. | chat demo Chat demosunu sadeleştirilmiş hali http://github.com/yuxel/snippets/blob/master/python/tornado/chat/
  • 31. | proje http://github.com/yuxel/feedget http://feedget.net/ (alpha)
  • 32. | kaynaklar http://www.tornadoweb.org/ http://github.com/facebook/tornado irc://irc.freenode.net/tornado
  • 33. | iletişim Osman Yüksel yuxel |ET| sonsuzdongu {DAT} com http://yuxel.net