├── .gitignore ├── README ├── async ├── .gitignore ├── README.rst ├── assincrono.py ├── assincrono_clo.py ├── assincrono_ge.py ├── assincrono_oo.py ├── flags │ ├── CIA_Flags_of_the_World.html │ ├── CIA_Flags_of_the_World_files │ │ ├── 1024_lefttop_background.jpg │ │ ├── 1024_righttop_background.jpg │ │ ├── 5_spacer.jpg │ │ ├── AJAXLibrary.js │ │ ├── DataEntryLibrary.js │ │ ├── SpryCollapsiblePanel.js │ │ ├── SpryCollapsiblePanel2.css │ │ ├── aa-lgflag.gif │ │ ├── ac-lgflag.gif │ │ ├── ae-lgflag.gif │ │ ├── af-lgflag.gif │ │ ├── ag-lgflag.gif │ │ ├── aj-lgflag.gif │ │ ├── al-lgflag.gif │ │ ├── am-lgflag.gif │ │ ├── an-lgflag.gif │ │ ├── ao-lgflag.gif │ │ ├── aq-lgflag.gif │ │ ├── ar-lgflag.gif │ │ ├── as-lgflag.gif │ │ ├── at-lgflag.gif │ │ ├── au-lgflag.gif │ │ ├── av-lgflag.gif │ │ ├── ax-lgflag.gif │ │ ├── ba-lgflag.gif │ │ ├── bandwidth_btn_off.gif │ │ ├── banner.gif │ │ ├── bb-lgflag.gif │ │ ├── bc-lgflag.gif │ │ ├── bd-lgflag.gif │ │ ├── be-lgflag.gif │ │ ├── bf-lgflag.gif │ │ ├── bg-lgflag.gif │ │ ├── bh-lgflag.gif │ │ ├── bk-lgflag.gif │ │ ├── bl-lgflag.gif │ │ ├── bm-lgflag.gif │ │ ├── bn-lgflag.gif │ │ ├── bo-lgflag.gif │ │ ├── bp-lgflag.gif │ │ ├── bq-lgflag.gif │ │ ├── br-lgflag.gif │ │ ├── bt-lgflag.gif │ │ ├── btn_country_on.jpg │ │ ├── btn_flag_on.jpg │ │ ├── bu-lgflag.gif │ │ ├── bv-lgflag.gif │ │ ├── bx-lgflag.gif │ │ ├── by-lgflag.gif │ │ ├── ca-lgflag.gif │ │ ├── cb-lgflag.gif │ │ ├── cc-lgflag.gif │ │ ├── cd-lgflag.gif │ │ ├── ce-lgflag.gif │ │ ├── cf-lgflag.gif │ │ ├── cg-lgflag.gif │ │ ├── ch-lgflag.gif │ │ ├── ci-lgflag.gif │ │ ├── cj-lgflag.gif │ │ ├── ck-lgflag.gif │ │ ├── cm-lgflag.gif │ │ ├── cn-lgflag.gif │ │ ├── co-lgflag.gif │ │ ├── cq-lgflag.gif │ │ ├── cr-lgflag.gif │ │ ├── cs-lgflag.gif │ │ ├── ct-lgflag.gif │ │ ├── cu-lgflag.gif │ │ ├── cv-lgflag.gif │ │ ├── cw-lgflag.gif │ │ ├── cy-lgflag.gif │ │ ├── da-lgflag.gif │ │ ├── dj-lgflag.gif │ │ ├── do-lgflag.gif │ │ ├── download_btn_off.gif │ │ ├── dr-lgflag.gif │ │ ├── dx-lgflag.gif │ │ ├── ec-lgflag.gif │ │ ├── ee-lgflag.gif │ │ ├── eg-lgflag.gif │ │ ├── ei-lgflag.gif │ │ ├── ek-lgflag.gif │ │ ├── en-lgflag.gif │ │ ├── er-lgflag.gif │ │ ├── es-lgflag.gif │ │ ├── et-lgflag.gif │ │ ├── ez-lgflag.gif │ │ ├── factbook.css │ │ ├── factbook_1024.css │ │ ├── fi-lgflag.gif │ │ ├── findDOM.js │ │ ├── fj-lgflag.gif │ │ ├── fk-lgflag.gif │ │ ├── flagsoftheworld.css │ │ ├── fm-lgflag.gif │ │ ├── fo-lgflag.gif │ │ ├── fp-lgflag.gif │ │ ├── fr-lgflag.gif │ │ ├── fs-lgflag.gif │ │ ├── ga-lgflag.gif │ │ ├── gb-lgflag.gif │ │ ├── gg-lgflag.gif │ │ ├── gh-lgflag.gif │ │ ├── gi-lgflag.gif │ │ ├── gj-lgflag.gif │ │ ├── gk-lgflag.gif │ │ ├── gl-lgflag.gif │ │ ├── gm-lgflag.gif │ │ ├── gold_gradiant.gif │ │ ├── gq-lgflag.gif │ │ ├── gr-lgflag.gif │ │ ├── gt-lgflag.gif │ │ ├── gv-lgflag.gif │ │ ├── gy-lgflag.gif │ │ ├── ha-lgflag.gif │ │ ├── hk-lgflag.gif │ │ ├── hm-lgflag.gif │ │ ├── ho-lgflag.gif │ │ ├── hr-lgflag.gif │ │ ├── hu-lgflag.gif │ │ ├── ic-lgflag.gif │ │ ├── id-lgflag.gif │ │ ├── im-lgflag.gif │ │ ├── in-lgflag.gif │ │ ├── io-lgflag.gif │ │ ├── ip-lgflag.gif │ │ ├── ir-lgflag.gif │ │ ├── is-lgflag.gif │ │ ├── it-lgflag.gif │ │ ├── iv-lgflag.gif │ │ ├── iz-lgflag.gif │ │ ├── ja-lgflag.gif │ │ ├── je-lgflag.gif │ │ ├── jm-lgflag.gif │ │ ├── jn-lgflag.gif │ │ ├── jo-lgflag.gif │ │ ├── jquery.js │ │ ├── ke-lgflag.gif │ │ ├── kg-lgflag.gif │ │ ├── kn-lgflag.gif │ │ ├── kr-lgflag.gif │ │ ├── ks-lgflag.gif │ │ ├── kt-lgflag.gif │ │ ├── ku-lgflag.gif │ │ ├── kv-lgflag.gif │ │ ├── kz-lgflag.gif │ │ ├── la-lgflag.gif │ │ ├── le-lgflag.gif │ │ ├── lg-lgflag.gif │ │ ├── lh-lgflag.gif │ │ ├── li-lgflag.gif │ │ ├── lnav_greybarBot1.gif │ │ ├── lo-lgflag.gif │ │ ├── ls-lgflag.gif │ │ ├── lt-lgflag.gif │ │ ├── lu-lgflag.gif │ │ ├── ly-lgflag.gif │ │ ├── ma-lgflag.gif │ │ ├── mc-lgflag.gif │ │ ├── md-lgflag.gif │ │ ├── mg-lgflag.gif │ │ ├── mh-lgflag.gif │ │ ├── mi-lgflag.gif │ │ ├── mj-lgflag.gif │ │ ├── mk-lgflag.gif │ │ ├── ml-lgflag.gif │ │ ├── mm_menu.js │ │ ├── mn-lgflag.gif │ │ ├── mo-lgflag.gif │ │ ├── mp-lgflag.gif │ │ ├── mr-lgflag.gif │ │ ├── mt-lgflag.gif │ │ ├── mu-lgflag.gif │ │ ├── mv-lgflag.gif │ │ ├── mx-lgflag.gif │ │ ├── my-lgflag.gif │ │ ├── mz-lgflag.gif │ │ ├── nav_arrows.gif │ │ ├── nav_style.css │ │ ├── nc-lgflag.gif │ │ ├── ne-lgflag.gif │ │ ├── newwindow.gif │ │ ├── nf-lgflag.gif │ │ ├── ng-lgflag.gif │ │ ├── nh-lgflag.gif │ │ ├── ni-lgflag.gif │ │ ├── nl-lgflag.gif │ │ ├── no-lgflag.gif │ │ ├── np-lgflag.gif │ │ ├── nr-lgflag.gif │ │ ├── ns-lgflag.gif │ │ ├── nu-lgflag.gif │ │ ├── nz-lgflag.gif │ │ ├── od-lgflag.gif │ │ ├── pa-lgflag.gif │ │ ├── pc-lgflag.gif │ │ ├── pe-lgflag.gif │ │ ├── pk-lgflag.gif │ │ ├── pl-lgflag.gif │ │ ├── pm-lgflag.gif │ │ ├── po-lgflag.gif │ │ ├── pp-lgflag.gif │ │ ├── print.css │ │ ├── print.gif │ │ ├── ps-lgflag.gif │ │ ├── pu-lgflag.gif │ │ ├── qa-lgflag.gif │ │ ├── ri-lgflag.gif │ │ ├── rm-lgflag.gif │ │ ├── rn-lgflag.gif │ │ ├── ro-lgflag.gif │ │ ├── rp-lgflag.gif │ │ ├── rq-lgflag.gif │ │ ├── rs-lgflag.gif │ │ ├── rw-lgflag.gif │ │ ├── sa-lgflag.gif │ │ ├── sb-lgflag.gif │ │ ├── sc-lgflag.gif │ │ ├── se-lgflag.gif │ │ ├── searchBtn.gif │ │ ├── sf-lgflag.gif │ │ ├── sg-lgflag.gif │ │ ├── sh-lgflag.gif │ │ ├── si-lgflag.gif │ │ ├── sk-lgflag.gif │ │ ├── sl-lgflag.gif │ │ ├── sm-lgflag.gif │ │ ├── sn-lgflag.gif │ │ ├── so-lgflag.gif │ │ ├── sp-lgflag.gif │ │ ├── st-lgflag.gif │ │ ├── su-lgflag.gif │ │ ├── sv-lgflag.gif │ │ ├── sw-lgflag.gif │ │ ├── sx-lgflag.gif │ │ ├── sy-lgflag.gif │ │ ├── sz-lgflag.gif │ │ ├── tb-lgflag.gif │ │ ├── td-lgflag.gif │ │ ├── th-lgflag.gif │ │ ├── ti-lgflag.gif │ │ ├── tk-lgflag.gif │ │ ├── tl-lgflag.gif │ │ ├── tn-lgflag.gif │ │ ├── to-lgflag.gif │ │ ├── tp-lgflag.gif │ │ ├── ts-lgflag.gif │ │ ├── tt-lgflag.gif │ │ ├── tu-lgflag.gif │ │ ├── tv-lgflag.gif │ │ ├── tw-lgflag.gif │ │ ├── tx-lgflag.gif │ │ ├── tz-lgflag.gif │ │ ├── ug-lgflag.gif │ │ ├── uk-lgflag.gif │ │ ├── um-lgflag.gif │ │ ├── up-lgflag.gif │ │ ├── us-lgflag.gif │ │ ├── uv-lgflag.gif │ │ ├── uy-lgflag.gif │ │ ├── uz-lgflag.gif │ │ ├── vc-lgflag.gif │ │ ├── ve-lgflag.gif │ │ ├── vi-lgflag.gif │ │ ├── vm-lgflag.gif │ │ ├── vq-lgflag.gif │ │ ├── vt-lgflag.gif │ │ ├── wa-lgflag.gif │ │ ├── wf-lgflag.gif │ │ ├── wq-lgflag.gif │ │ ├── ws-lgflag.gif │ │ ├── wz-lgflag.gif │ │ ├── ym-lgflag.gif │ │ ├── za-lgflag.gif │ │ └── zi-lgflag.gif │ ├── listar_bandeiras.py │ └── servidor_lento.py ├── futures.py ├── multiproc.py ├── multiproc_queue.py ├── siglas.txt ├── sincrono.py ├── threads.py ├── threads_queue.py └── utilflags.py ├── atributos ├── atrib_dinamicos.py ├── checkedprops.py ├── descr_leitura.py ├── descr_leitura2.py ├── descr_natural.py ├── descr_quantidade.py ├── descritores.py ├── exercicios │ ├── aluno.py │ ├── contato.py │ ├── email.py │ ├── idade.py │ ├── jsobject.py │ ├── lista_ex_2.rst │ └── mod11.py ├── gato.py ├── gato_v2.py ├── granel │ ├── pedido.py │ ├── pedido_java.py │ └── pedido_v2.py ├── idade.py ├── java │ ├── AcessaPrivado.java │ ├── AcessaPrivado.py │ ├── ListaPrivados.java │ ├── ListaPrivados.py │ ├── MudaPrivado.java │ ├── MudaPrivado.py │ └── ObjetoSecreto.java ├── metaclasses │ ├── README │ ├── pedido0.py │ ├── pedido1.py │ ├── pedido2.py │ ├── pedido3.py │ ├── pedido4.py │ ├── pedido5.py │ ├── pedido6.py │ ├── pedido7.py │ ├── pedido8.py │ └── pedido9.py ├── ordprops.py ├── prop_leitura.py └── t0 │ ├── descritores.py │ ├── pedido.py │ ├── pedido2.py │ └── pedido4.py ├── baralho_listcomp.py ├── funcional ├── funcao_1a_classe.py ├── lambda.py ├── roman_closure.py └── sort.py ├── iteraveis ├── baralho.py ├── baralho_iter_genexp.py ├── baralho_iter_gerador.py ├── baralho_iter_oo.py ├── baralho_misturado.py ├── busca_bin.py ├── demo_genexp.py ├── demo_iter2.py ├── demo_iter2_partial.py ├── genexp_x_listcomp.py ├── lista_ex_1.rst ├── lista_ord.py ├── repl_batch.py └── texto.py ├── metaprog ├── execucao.py ├── execucao_import.py ├── execucao_vars.py ├── lista_tipada.py ├── ordinais.py └── ordinais2.py └── templates └── format.rst /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.class 3 | .tornado 4 | .env 5 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Exemplos do curso "Python para quem sabe Python". 2 | 3 | Leia mais em: 4 | 5 | http://turing.com.br/wiki/index.php?title=Python_para_quem_sabe_Python 6 | ou 7 | http://j.mp/ppqsp 8 | -------------------------------------------------------------------------------- /async/.gitignore: -------------------------------------------------------------------------------- 1 | bandeiras/ 2 | tornado.env 3 | -------------------------------------------------------------------------------- /async/README.rst: -------------------------------------------------------------------------------- 1 | Implementações a fazer 2 | ---------------------- 3 | 4 | Com futures: 5 | http://www.python.org/dev/peps/pep-3148/ 6 | 7 | Com gevent: 8 | https://github.com/gwik/geventhttpclient 9 | 10 | -------------------------------------------------------------------------------- /async/assincrono.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | from tornado import httpclient, ioloop 4 | 5 | from utilflags import ler_siglas, salvar, reportar, BASE_URL 6 | 7 | qt_bytes = 0 8 | qt_arqs = 0 9 | conj_baixar = set() 10 | 11 | def processar(response): 12 | global qt_bytes, qt_arqs 13 | nome = response.request.url[len(BASE_URL):] 14 | if response.error: 15 | print 'Erro: ', response.error 16 | print '\tTentando de novo...', response.request.url 17 | httpclient.AsyncHTTPClient().fetch(response.request.url, processar) 18 | else: 19 | qt_bytes += salvar(nome, response.body) 20 | qt_arqs += 1 21 | print '\t\t\t', nome, '--> salvo' 22 | conj_baixar.discard(nome) 23 | if not conj_baixar: 24 | ioloop.IOLoop.instance().stop() 25 | 26 | def baixar(qtd): 27 | """ busca a quantidade ``qtd`` de bandeiras """ 28 | 29 | cliente = httpclient.AsyncHTTPClient() 30 | 31 | for num, sigla in enumerate(ler_siglas(qtd), 1): 32 | nome = sigla + '-lgflag.gif' 33 | print '\t%3d\t%s' % (num, nome) 34 | url = BASE_URL+nome 35 | conj_baixar.add(nome) 36 | cliente.fetch(url, processar) 37 | 38 | ioloop.IOLoop.instance().start() 39 | return qt_bytes, qt_arqs 40 | 41 | if __name__=='__main__': 42 | reportar(baixar) 43 | 44 | 45 | """ 46 | $ python sincrono.py 10 47 | baixando 10 arquivos... 48 | 1 aa-lgflag.gif 49 | 2 ac-lgflag.gif 50 | 3 ae-lgflag.gif 51 | ... 52 | 96442 bytes baixados em 10 arquivos 53 | tempo transcorrido: 8.83s 54 | (tornado.env)lontra:async luciano$ python assincrono.py 10 55 | baixando 10 arquivos... 56 | 1 aa-lgflag.gif 57 | 2 ac-lgflag.gif 58 | 3 ae-lgflag.gif 59 | ... 60 | ac-lgflag.gif --> salvo 61 | ae-lgflag.gif --> salvo 62 | aa-lgflag.gif --> salvo 63 | ... 64 | 96442 bytes baixados em 10 arquivos 65 | tempo transcorrido: 1.23s 66 | """ 67 | 68 | -------------------------------------------------------------------------------- /async/assincrono_clo.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | from tornado import httpclient, ioloop 4 | 5 | from utilflags import ler_siglas, salvar, reportar, BASE_URL 6 | 7 | qt_bytes = 0 8 | qt_arqs = 0 9 | conj_baixar = set() 10 | 11 | def processar(response, nome, numero): 12 | global qt_bytes, qt_arqs 13 | if response.error: 14 | print 'Erro: ', response.error 15 | print '\tTentando de novo...', response.request.url 16 | httpclient.AsyncHTTPClient().fetch(response.request.url, processar) 17 | else: 18 | qt_bytes += salvar(nome, response.body) 19 | qt_arqs += 1 20 | print '\t\t\t%3d\t%s --> salvo' % (numero, nome) 21 | conj_baixar.discard(nome) 22 | if not conj_baixar: 23 | ioloop.IOLoop.instance().stop() 24 | 25 | def faz_processar(nome, numero): 26 | def _interna(request): 27 | processar(request, nome, numero) 28 | return _interna 29 | 30 | def baixar(qtd): 31 | """ busca a quantidade ``qtd`` de bandeiras """ 32 | 33 | http_client = httpclient.AsyncHTTPClient() 34 | 35 | for num, sigla in enumerate(ler_siglas(qtd), 1): 36 | nome = sigla + '-lgflag.gif' 37 | print '\t%3d\t%s' % (num, nome) 38 | url = BASE_URL+nome 39 | conj_baixar.add(nome) 40 | http_client.fetch(url, faz_processar(nome, num)) 41 | 42 | ioloop.IOLoop.instance().start() 43 | return qt_bytes, qt_arqs 44 | 45 | if __name__=='__main__': 46 | reportar(baixar) 47 | 48 | 49 | -------------------------------------------------------------------------------- /async/assincrono_ge.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | from tornado import httpclient, ioloop, gen 4 | 5 | from utilflags import ler_siglas, salvar, reportar, BASE_URL 6 | 7 | qt_bytes = 0 8 | qt_arqs = 0 9 | conj_baixar = set() 10 | 11 | @gen.engine 12 | def processar(cliente, nome, numero): 13 | global qt_bytes, qt_arqs 14 | print '\t%3d\t%s' % (numero, nome) 15 | conj_baixar.add(nome) 16 | url = BASE_URL+nome 17 | response = yield gen.Task(cliente.fetch, url) 18 | if response.error: 19 | print 'Erro: ', response.error 20 | print '\tTentando de novo...', response.request.url 21 | http_client.fetch(response.request.url, handle_request) 22 | else: 23 | qt_bytes += salvar(nome, response.body) 24 | qt_arqs += 1 25 | print '\t\t\t%3d\t%s --> salvo' % (numero, nome) 26 | conj_baixar.discard(nome) 27 | if not conj_baixar: 28 | ioloop.IOLoop.instance().stop() 29 | 30 | def baixar(qtd): 31 | """ busca a quantidade ``qtd`` de bandeiras """ 32 | 33 | cliente = httpclient.AsyncHTTPClient() 34 | 35 | for num, sigla in enumerate(ler_siglas(qtd), 1): 36 | nome = sigla + '-lgflag.gif' 37 | processar(cliente, nome, num) 38 | 39 | ioloop.IOLoop.instance().start() 40 | return qt_bytes, qt_arqs 41 | 42 | if __name__=='__main__': 43 | reportar(baixar) 44 | -------------------------------------------------------------------------------- /async/assincrono_oo.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | from tornado import httpclient, ioloop 4 | 5 | from utilflags import ler_siglas, salvar, reportar, BASE_URL 6 | 7 | class Processador(object): 8 | qt_bytes = 0 9 | qt_arqs = 0 10 | conj_baixar = set() 11 | 12 | def __init__(self, nome, numero): 13 | Processador.conj_baixar.add(nome) 14 | self.nome = nome 15 | self.numero = numero 16 | 17 | def processar(self, response): 18 | if response.error: 19 | print 'Erro: ', response.error 20 | print '\tTentando de novo...', response.request.url 21 | http_client.fetch(response.request.url, self.processar) 22 | else: 23 | Processador.qt_bytes += salvar(self.nome, response.body) 24 | Processador.qt_arqs += 1 25 | print '\t\t\t%3d\t%s --> salvo' % (self.numero, self.nome) 26 | Processador.conj_baixar.discard(self.nome) 27 | if not Processador.conj_baixar: 28 | ioloop.IOLoop.instance().stop() 29 | 30 | def baixar(qtd): 31 | """ busca a quantidade ``qtd`` de bandeiras """ 32 | 33 | http_client = httpclient.AsyncHTTPClient() 34 | 35 | for num, sigla in enumerate(ler_siglas(qtd), 1): 36 | nome = sigla + '-lgflag.gif' 37 | print '\t%3d\t%s' % (num, nome) 38 | url = BASE_URL+nome 39 | proc = Processador(nome, num) 40 | http_client.fetch(url, proc.processar) 41 | 42 | ioloop.IOLoop.instance().start() 43 | return Processador.qt_bytes, Processador.qt_arqs 44 | 45 | if __name__=='__main__': 46 | reportar(baixar) 47 | 48 | 49 | -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/1024_lefttop_background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/1024_lefttop_background.jpg -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/1024_righttop_background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/1024_righttop_background.jpg -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/5_spacer.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/5_spacer.jpg -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/DataEntryLibrary.js: -------------------------------------------------------------------------------- 1 | // JavaScript Document 2 | 3 | function trim(str) 4 | { 5 | while (str.charAt(0) == ' ' || str.charAt(0) == '\t' || str.charAt(0) == '\n') 6 | str = str.substring(1, str.length); 7 | 8 | while (str.charAt(str.length-1) == ' ' || str.charAt(str.length-1) == '\t' || str.charAt(str.length-1) == '\n') 9 | str = str.substring(0, str.length); 10 | 11 | return str; 12 | } 13 | 14 | 15 | 16 | 17 | function regTrim(str) 18 | { 19 | var DD = str; 20 | 21 | DD = DD.replace(/^\s+|\s+$/g,""); 22 | 23 | return DD; 24 | } 25 | 26 | 27 | 28 | 29 | function focusFirstField( ) 30 | { 31 | // Locate the first field on the first form and give it focus 32 | if (document.forms.length > 0) 33 | { 34 | // Find the first form field that's not hidden so focus can be given 35 | for (var i = 0; i < document.forms[0].elements.length; i++) 36 | { 37 | if (document.forms[0].elements[i].type && document.forms[0].elements[i].type.indexOf("hidden") < 0) // "type" may not be defined in all elements of a form (fieldsets, e.g.) 38 | { 39 | document.forms[0].elements[i].focus(); 40 | break; 41 | } 42 | } 43 | } 44 | return true; 45 | } 46 | 47 | 48 | 49 | 50 | function isTextFieldEmpty(obj) 51 | { 52 | var retval; 53 | var objValue; 54 | 55 | objValue = trim(obj.value); 56 | if (objValue.length == 0) 57 | retval = true; 58 | else 59 | retval = false; 60 | 61 | return retval; 62 | } 63 | 64 | 65 | 66 | 67 | function isEmail(obj) 68 | { 69 | var retval; 70 | 71 | if (isTextFieldEmpty(obj)) 72 | retval = false; 73 | else if (obj.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) 74 | retval = true; 75 | else 76 | retval = false; 77 | 78 | return retval; 79 | } 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/SpryCollapsiblePanel2.css: -------------------------------------------------------------------------------- 1 | @charset "UTF-8"; 2 | 3 | /* SpryCollapsiblePanel.css - Revision: Spry Preview Release 1.4 */ 4 | 5 | /* Copyright (c) 2006. Adobe Systems Incorporated. All rights reserved. */ 6 | 7 | /* This is the selector for the main CollapsiblePanel container. For our 8 | * default style, the CollapsiblePanel is responsible for drawing the borders 9 | * around the widget. 10 | * 11 | * If you want to constrain the width of the CollapsiblePanel widget, set a width on 12 | * the CollapsiblePanel container. By default, our CollapsiblePanel expands horizontally to fill 13 | * up available space. 14 | * 15 | * The name of the class ("CollapsiblePanel") used in this selector is not necessary 16 | * to make the widget function. You can use any class name you want to style the 17 | * CollapsiblePanel container. 18 | */ 19 | .CollapsiblePanel { 20 | margin: 0px; 21 | padding: 0px; 22 | width: auto; 23 | } 24 | 25 | .CollapsiblePanel .cateogry a:link { 26 | text-decoration: underline; 27 | letter-spacing: 1px; 28 | } 29 | 30 | /* This is the selector for the CollapsiblePanelTab. This container houses 31 | * the title for the panel. This is also the container that the user clicks 32 | * on to open or close the panel. 33 | * 34 | * The name of the class ("CollapsiblePanelTab") used in this selector is not necessary 35 | * to make the widget function. You can use any class name you want to style an 36 | * CollapsiblePanel panel tab container. 37 | */ 38 | .CollapsiblePanelTab { 39 | height: 30px; 40 | cursor: pointer; 41 | -moz-user-select: none; 42 | -khtml-user-select: none; 43 | color: #FFFFFF; 44 | text-transform:none; 45 | border-bottom: 1px solid white; 46 | background-image: url(../graphics/open.jpg); 47 | background-position: right; 48 | background-repeat: no-repeat; 49 | /* padding-right: 5px; 50 | margin-right: 5px;*/ 51 | } 52 | 53 | /* This is the selector for a CollapsiblePanel's Content area. It's important to note that 54 | * you should never put any padding on the content area element if you plan to 55 | * use the CollapsiblePanel's open/close animations. Placing a non-zero padding on the content 56 | * element can cause the CollapsiblePanel to abruptly grow in height while the panels animate. 57 | * 58 | * The name of the class ("CollapsiblePanelContent") used in this selector is not necessary 59 | * to make the widget function. You can use any class name you want to style a 60 | * CollapsiblePanel content container. 61 | */ 62 | .CollapsiblePanelContent { 63 | margin: 0px; 64 | padding: 0px; 65 | text-align: left; 66 | margin-left: -2px; 67 | } 68 | 69 | /* An anchor tag can be used inside of a CollapsiblePanelTab so that the 70 | * keyboard focus ring appears *inside* the tab instead of around the tab. 71 | * This is an example of how to make the text within the anchor tag look 72 | * like non-anchor (normal) text. 73 | */ 74 | .CollapsiblePanelTab a:link { 75 | text-decoration: none; 76 | } 77 | 78 | /* This is an example of how to change the appearance of the panel tab that is 79 | * currently open. The class "CollapsiblePanelOpen" is programatically added and removed 80 | * from panels as the user clicks on the tabs within the CollapsiblePanel. 81 | */ 82 | .CollapsiblePanelOpen .CollapsiblePanelTab { 83 | color: #FFFFFF; 84 | background-image: url(../graphics/close.jpg); 85 | background-position: 618px 8px; 86 | } 87 | 88 | /* This is an example of how to change the appearance of the panel tab as the 89 | * mouse hovers over it. The class "CollapsiblePanelTabHover" is programatically added 90 | * and removed from panel tab containers as the mouse enters and exits the tab container. 91 | */ 92 | .CollapsiblePanelTabHover, .CollapsiblePanelOpen .CollapsiblePanelTabHover { 93 | color: #FFFFFF; 94 | } 95 | 96 | /* This is an example of how to change the appearance of all the panel tabs when the 97 | * CollapsiblePanel has focus. The "CollapsiblePanelFocused" class is programatically added and removed 98 | * whenever the CollapsiblePanel gains or loses keyboard focus. 99 | */ 100 | .CollapsiblePanelFocused .CollapsiblePanelTab { 101 | color: #FFFFFF; 102 | } 103 | 104 | .CollapsiblePanelClosed .CollapsiblePanelTab { 105 | color: #FFFFFF; 106 | background-image: url(../graphics/open.jpg); 107 | background-position: 618px 8px; 108 | 109 | } -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/aa-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/aa-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ac-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ac-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ae-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ae-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/af-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/af-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ag-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ag-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/aj-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/aj-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/al-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/al-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/am-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/am-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/an-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/an-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ao-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ao-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/aq-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/aq-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ar-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ar-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/as-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/as-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/at-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/at-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/au-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/au-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/av-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/av-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ax-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ax-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ba-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ba-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/bandwidth_btn_off.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/bandwidth_btn_off.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/banner.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/banner.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/bb-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/bb-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/bc-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/bc-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/bd-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/bd-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/be-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/be-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/bf-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/bf-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/bg-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/bg-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/bh-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/bh-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/bk-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/bk-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/bl-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/bl-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/bm-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/bm-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/bn-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/bn-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/bo-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/bo-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/bp-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/bp-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/bq-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/bq-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/br-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/br-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/bt-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/bt-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/btn_country_on.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/btn_country_on.jpg -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/btn_flag_on.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/btn_flag_on.jpg -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/bu-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/bu-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/bv-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/bv-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/bx-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/bx-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/by-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/by-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ca-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ca-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/cb-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/cb-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/cc-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/cc-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/cd-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/cd-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ce-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ce-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/cf-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/cf-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/cg-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/cg-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ch-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ch-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ci-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ci-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/cj-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/cj-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ck-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ck-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/cm-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/cm-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/cn-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/cn-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/co-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/co-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/cq-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/cq-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/cr-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/cr-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/cs-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/cs-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ct-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ct-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/cu-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/cu-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/cv-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/cv-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/cw-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/cw-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/cy-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/cy-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/da-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/da-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/dj-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/dj-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/do-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/do-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/download_btn_off.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/download_btn_off.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/dr-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/dr-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/dx-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/dx-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ec-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ec-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ee-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ee-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/eg-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/eg-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ei-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ei-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ek-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ek-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/en-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/en-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/er-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/er-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/es-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/es-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/et-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/et-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ez-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ez-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/fi-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/fi-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/fj-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/fj-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/fk-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/fk-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/flagsoftheworld.css: -------------------------------------------------------------------------------- 1 | /* flags of the world */ 2 | .flagsoftheworld_bkgrnd { 3 | background-image: url(../graphics/flagsoftheworld_bkgrnd.jpg); 4 | background-repeat: no-repeat; 5 | background-position: center center; 6 | text-align: center; 7 | vertical-align: middle; 8 | } 9 | 10 | .toggleopacity img{ 11 | filter:progid:DXImageTransform.Microsoft.Alpha(opacity=40); 12 | -moz-opacity: 0.5; 13 | border:none; 14 | } 15 | 16 | .toggleopacity:hover img{ 17 | filter:progid:DXImageTransform.Microsoft.Alpha(opacity=100); 18 | -moz-opacity: 1; 19 | border:none; 20 | 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/fm-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/fm-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/fo-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/fo-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/fp-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/fp-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/fr-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/fr-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/fs-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/fs-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ga-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ga-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/gb-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/gb-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/gg-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/gg-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/gh-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/gh-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/gi-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/gi-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/gj-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/gj-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/gk-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/gk-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/gl-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/gl-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/gm-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/gm-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/gold_gradiant.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/gold_gradiant.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/gq-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/gq-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/gr-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/gr-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/gt-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/gt-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/gv-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/gv-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/gy-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/gy-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ha-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ha-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/hk-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/hk-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/hm-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/hm-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ho-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ho-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/hr-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/hr-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/hu-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/hu-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ic-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ic-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/id-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/id-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/im-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/im-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/in-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/in-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/io-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/io-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ip-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ip-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ir-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ir-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/is-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/is-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/it-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/it-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/iv-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/iv-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/iz-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/iz-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ja-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ja-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/je-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/je-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/jm-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/jm-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/jn-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/jn-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/jo-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/jo-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/jquery.js: -------------------------------------------------------------------------------- 1 | /* jquery.imagefit 2 | * 3 | * Version 0.2 by Oliver Boermans 4 | * 5 | * Extends jQuery 6 | * 7 | */ 8 | (function($) { 9 | $.fn.imagefit = function(options) { 10 | var fit = { 11 | all : function(imgs){ 12 | imgs.each(function(){ 13 | fit.one(this); 14 | }) 15 | }, 16 | one : function(img){ 17 | $(img) 18 | .width('100%').each(function() 19 | { 20 | $(this).height(Math.round( 21 | $(this).attr('startheight')*($(this).width()/$(this).attr('startwidth'))) 22 | ); 23 | }) 24 | } 25 | }; 26 | 27 | this.each(function(){ 28 | var container = this; 29 | 30 | // store list of contained images (excluding those in tables) 31 | var imgs = $('img', container).not($("table img")); 32 | 33 | // store initial dimensions on each image 34 | imgs.each(function(){ 35 | $(this).attr('startwidth', $(this).width()) 36 | .attr('startheight', $(this).height()) 37 | .css('max-width', $(this).attr('startwidth')+"px"); 38 | 39 | fit.one(this); 40 | }); 41 | // Re-adjust when window width is changed 42 | $(window).bind('resize', function(){ 43 | fit.all(imgs); 44 | }); 45 | }); 46 | return this; 47 | }; 48 | })(jQuery); -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ke-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ke-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/kg-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/kg-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/kn-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/kn-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/kr-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/kr-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ks-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ks-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/kt-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/kt-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ku-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ku-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/kv-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/kv-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/kz-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/kz-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/la-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/la-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/le-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/le-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/lg-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/lg-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/lh-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/lh-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/li-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/li-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/lnav_greybarBot1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/lnav_greybarBot1.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/lo-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/lo-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ls-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ls-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/lt-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/lt-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/lu-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/lu-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ly-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ly-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ma-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ma-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/mc-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/mc-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/md-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/md-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/mg-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/mg-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/mh-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/mh-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/mi-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/mi-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/mj-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/mj-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/mk-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/mk-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ml-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ml-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/mn-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/mn-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/mo-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/mo-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/mp-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/mp-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/mr-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/mr-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/mt-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/mt-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/mu-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/mu-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/mv-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/mv-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/mx-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/mx-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/my-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/my-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/mz-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/mz-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/nav_arrows.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/nav_arrows.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/nc-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/nc-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ne-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ne-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/newwindow.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/newwindow.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/nf-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/nf-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ng-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ng-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/nh-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/nh-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ni-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ni-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/nl-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/nl-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/no-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/no-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/np-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/np-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/nr-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/nr-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ns-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ns-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/nu-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/nu-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/nz-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/nz-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/od-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/od-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/pa-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/pa-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/pc-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/pc-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/pe-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/pe-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/pk-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/pk-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/pl-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/pl-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/pm-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/pm-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/po-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/po-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/pp-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/pp-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/print.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/print.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ps-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ps-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/pu-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/pu-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/qa-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/qa-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ri-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ri-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/rm-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/rm-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/rn-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/rn-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ro-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ro-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/rp-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/rp-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/rq-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/rq-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/rs-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/rs-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/rw-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/rw-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/sa-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/sa-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/sb-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/sb-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/sc-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/sc-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/se-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/se-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/searchBtn.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/searchBtn.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/sf-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/sf-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/sg-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/sg-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/sh-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/sh-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/si-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/si-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/sk-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/sk-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/sl-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/sl-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/sm-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/sm-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/sn-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/sn-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/so-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/so-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/sp-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/sp-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/st-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/st-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/su-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/su-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/sv-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/sv-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/sw-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/sw-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/sx-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/sx-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/sy-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/sy-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/sz-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/sz-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/tb-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/tb-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/td-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/td-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/th-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/th-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ti-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ti-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/tk-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/tk-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/tl-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/tl-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/tn-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/tn-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/to-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/to-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/tp-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/tp-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ts-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ts-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/tt-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/tt-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/tu-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/tu-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/tv-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/tv-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/tw-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/tw-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/tx-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/tx-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/tz-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/tz-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ug-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ug-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/uk-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/uk-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/um-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/um-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/up-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/up-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/us-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/us-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/uv-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/uv-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/uy-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/uy-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/uz-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/uz-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/vc-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/vc-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ve-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ve-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/vi-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/vi-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/vm-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/vm-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/vq-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/vq-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/vt-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/vt-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/wa-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/wa-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/wf-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/wf-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/wq-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/wq-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ws-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ws-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/wz-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/wz-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/ym-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/ym-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/za-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/za-lgflag.gif -------------------------------------------------------------------------------- /async/flags/CIA_Flags_of_the_World_files/zi-lgflag.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oturing/ppqsp/5d6b9b9c536cc314c21fb450db5761b746514c40/async/flags/CIA_Flags_of_the_World_files/zi-lgflag.gif -------------------------------------------------------------------------------- /async/flags/listar_bandeiras.py: -------------------------------------------------------------------------------- 1 | 2 | import re 3 | 4 | BASE_URL = ('https://www.cia.gov/library/publications/the-world-factbook' 5 | '/graphics/flags/large/') 6 | 7 | re_flag = re.compile(r'src="\.\./graphics/flags/large/([^"]+)"') 8 | 9 | with open('flagsoftheworld.html') as arq_html: 10 | html = arq_html.read() 11 | 12 | res = re_flag.findall(html) 13 | for nome in res: 14 | print nome 15 | -------------------------------------------------------------------------------- /async/flags/servidor_lento.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | """ 5 | Este servidor introduz atrasos nas requisições GET. 6 | """ 7 | 8 | import SimpleHTTPServer 9 | import SocketServer 10 | import time 11 | 12 | PORT = 8000 13 | 14 | ATRASO = 2 # em segundos 15 | 16 | class HandlerLento(SimpleHTTPServer.SimpleHTTPRequestHandler): 17 | def do_GET(self): 18 | print 'dormindo %ss...' % ATRASO 19 | time.sleep(ATRASO) 20 | SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self) 21 | 22 | httpd = SocketServer.TCPServer(('', PORT), HandlerLento) 23 | 24 | print 'servindo na porta', PORT 25 | httpd.serve_forever() 26 | -------------------------------------------------------------------------------- /async/futures.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | import contextlib 4 | import urllib2 5 | import concurrent.futures # usando backport https://pypi.python.org/pypi/futures 6 | 7 | from utilflags import ler_siglas, salvar, reportar, BASE_URL 8 | 9 | 10 | def baixar_uma(nome): 11 | url = BASE_URL+nome 12 | with contextlib.closing(urllib2.urlopen(url)) as img_orig: 13 | return img_orig.read() 14 | 15 | def baixar(qtd): 16 | """ busca e salva a quantidade ``qtd`` de bandeiras """ 17 | 18 | qt_bytes = 0 19 | qt_arqs = 0 20 | 21 | with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor: 22 | 23 | pendentes = {} 24 | for (numero, sigla) in enumerate(ler_siglas(qtd), 1): 25 | nome = sigla + '-lgflag.gif' 26 | pendentes[executor.submit(baixar_uma, nome)] = numero, nome 27 | print '\t%3d\t%s' % (numero, nome) 28 | 29 | for future in concurrent.futures.as_completed(pendentes): 30 | numero, nome = pendentes[future] 31 | try: 32 | bytes = future.result() 33 | except Exception as exc: 34 | print('gerou erro ao baixar %s (#%s): %s' % (nome, numero, exc)) 35 | else: 36 | qt_bytes += salvar(nome, bytes) 37 | qt_arqs += 1 38 | print '\t\t\t%3d\t%s --> salvo' % (numero, nome) 39 | 40 | return qt_bytes, qt_arqs 41 | 42 | if __name__=='__main__': 43 | reportar(baixar) 44 | 45 | """ 46 | $ python sincrono_queue.py 3 47 | baixando 3 arquivos... 48 | 1 aa-lgflag.gif 49 | 2 ac-lgflag.gif 50 | 3 ae-lgflag.gif 51 | 2 ac-lgflag.gif --> salvo 52 | 1 aa-lgflag.gif --> salvo 53 | 3 ae-lgflag.gif --> salvo 54 | 11889 bytes baixados em 3 arquivos 55 | tempo transcorrido: 0.93s 56 | 57 | """ 58 | -------------------------------------------------------------------------------- /async/multiproc.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | import contextlib 4 | import urllib2 5 | import multiprocessing 6 | import time 7 | 8 | from utilflags import ler_siglas, salvar, reportar, BASE_URL 9 | 10 | qt_bytes = 0 11 | qt_arqs = 0 12 | conj_baixar = set() 13 | 14 | def baixar_uma(nome, numero): 15 | global qt_bytes, qt_arqs 16 | url = BASE_URL+nome 17 | with contextlib.closing(urllib2.urlopen(url)) as img_orig: 18 | img = img_orig.read() 19 | qt_bytes += salvar(nome, img) 20 | qt_arqs += 1 21 | print '\t\t\t%3d\t%s --> salvo' % (numero, nome) 22 | print conj_baixar 23 | conj_baixar.discard(nome) 24 | 25 | # GNU/Linux e Mac OSX suportam poucas centenas de threads 26 | MAX_THREADS = 100 27 | 28 | def baixar(qtd): 29 | """ busca e salva a quantidade ``qtd`` de bandeiras """ 30 | 31 | assert qtd <= MAX_THREADS, 'limite: %s downloads paralelos' % MAX_THREADS 32 | tarefas = [] 33 | for num, sigla in enumerate(ler_siglas(qtd), 1): 34 | # baixar bandeiras com inicial 'a' ou 'b' 35 | nome = sigla + '-lgflag.gif' 36 | print '\t%3d\t%s' % (num, nome) 37 | conj_baixar.add(nome) 38 | tarefa = multiprocessing.Process(target=baixar_uma, args=(nome, num)) 39 | tarefa.start() 40 | tarefas.append(tarefa) 41 | 42 | while conj_baixar: 43 | print len(conj_baixar) 44 | time.sleep(1) 45 | 46 | for tarefa in tarefas: 47 | tarefa.terminate() 48 | 49 | return qt_bytes, qt_arqs 50 | 51 | if __name__=='__main__': 52 | reportar(baixar) 53 | 54 | """ 55 | $ python sincrono_threads.py 3 56 | baixando 3 arquivos... 57 | 1 aa-lgflag.gif 58 | 2 ac-lgflag.gif 59 | 3 ae-lgflag.gif 60 | 1 aa-lgflag.gif --> salvo 61 | 2 ac-lgflag.gif --> salvo 62 | 3 ae-lgflag.gif --> salvo 63 | 11889 bytes baixados em 3 arquivos 64 | tempo transcorrido: 1.08s 65 | """ 66 | -------------------------------------------------------------------------------- /async/multiproc_queue.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | import contextlib 4 | import urllib2 5 | import multiprocessing 6 | from Queue import Queue 7 | 8 | from utilflags import ler_siglas, salvar, reportar, BASE_URL 9 | 10 | qt_bytes = 0 11 | qt_arqs = 0 12 | fila = Queue() 13 | 14 | def baixar_uma(nome, numero): 15 | global qt_bytes, qt_arqs 16 | url = BASE_URL+nome 17 | with contextlib.closing(urllib2.urlopen(url)) as img_orig: 18 | img = img_orig.read() 19 | qt_bytes += salvar(nome, img) 20 | qt_arqs += 1 21 | print '\t\t\t%3d\t%s --> salvo' % (numero, nome) 22 | 23 | NUM_THREADS = 10 24 | 25 | def worker(): 26 | while True: 27 | nome, numero = fila.get() 28 | baixar_uma(nome, numero) 29 | fila.task_done() 30 | 31 | def baixar(qtd): 32 | """ busca e salva a quantidade ``qtd`` de bandeiras """ 33 | 34 | # criar threads 35 | for i in range(NUM_THREADS): 36 | tarefa = multiprocessing.Process(target=worker) 37 | tarefa.daemon = True 38 | tarefa.start() 39 | 40 | # enfileirar tarefas 41 | for numero, sigla in enumerate(ler_siglas(qtd), 1): 42 | # baixar bandeiras com inicial 'a' ou 'b' 43 | nome = sigla + '-lgflag.gif' 44 | print '\t%3d\t%s' % (numero, nome) 45 | fila.put((nome, numero)) 46 | 47 | fila.join() 48 | 49 | return qt_bytes, qt_arqs 50 | 51 | if __name__=='__main__': 52 | reportar(baixar) 53 | 54 | """ 55 | $ python sincrono_queue.py 3 56 | baixando 3 arquivos... 57 | 1 aa-lgflag.gif 58 | 2 ac-lgflag.gif 59 | 3 ae-lgflag.gif 60 | 2 ac-lgflag.gif --> salvo 61 | 1 aa-lgflag.gif --> salvo 62 | 3 ae-lgflag.gif --> salvo 63 | 11889 bytes baixados em 3 arquivos 64 | tempo transcorrido: 0.93s 65 | 66 | """ 67 | -------------------------------------------------------------------------------- /async/siglas.txt: -------------------------------------------------------------------------------- 1 | aa ac ae af ag aj al am an ao aq ar as at au av ax ba bb bc bd be bf bg bh bk 2 | bl bm bn bo bp bq br bt bu bv bx by ca cb cc cd ce cf cg ch ci cj ck cm cn co 3 | cq cr cs ct cu cv cw cy da dj do dr dx ec ee eg ei ek en er es et ez fi fj fk 4 | fm fo fp fr fs ga gb gg gh gi gj gk gl gm gq gr gt gv gy ha hk hm ho hr hu ic 5 | id im in io ip ir is it iv iz ja je jm jn jo ke kg kn kr ks kt ku kv kz la le 6 | lg lh li lo ls lt lu ly ma mc md mg mh mi mj mk ml mn mo mp mr mt mu mv mx my 7 | mz nc ne nf ng nh ni nl no np nr ns nu nz od pa pc pe pk pl pm po pp ps pu qa 8 | ri rm rn ro rp rq rs rw sa sb sc se sf sg sh si sk sl sm sn so sp st su sv sw 9 | sx sy sz tb td th ti tk tl tn to tp ts tt tu tv tw tx tz ug uk um up us uv uy 10 | uz vc ve vi vm vq vt wa wf wq ws wz ym za zi 11 | -------------------------------------------------------------------------------- /async/sincrono.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | import contextlib 4 | import urllib2 5 | 6 | from utilflags import ler_siglas, salvar, reportar, BASE_URL 7 | 8 | def baixar(qtd): 9 | """ busca e salva a quantidade ``qtd`` de bandeiras """ 10 | qt_bytes = 0 11 | qt_arqs = 0 12 | 13 | for num, sigla in enumerate(ler_siglas(qtd), 1): 14 | nome = sigla + '-lgflag.gif' 15 | print '\t%3d\t%s' % (num, nome) 16 | url = BASE_URL+nome 17 | with contextlib.closing(urllib2.urlopen(url)) as img_orig: 18 | img = img_orig.read() 19 | qt_bytes += salvar(nome, img) 20 | qt_arqs += 1 21 | 22 | return qt_bytes, qt_arqs 23 | 24 | if __name__=='__main__': 25 | reportar(baixar) 26 | 27 | """ 28 | $ python sincrono.py 3 29 | baixando 3 arquivos... 30 | 1 aa-lgflag.gif 31 | 2 ac-lgflag.gif 32 | 3 ae-lgflag.gif 33 | 11889 bytes baixados em 3 arquivos 34 | tempo transcorrido: 12.62s 35 | 36 | """ 37 | -------------------------------------------------------------------------------- /async/threads.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | import contextlib 4 | import urllib2 5 | import threading 6 | 7 | from utilflags import ler_siglas, salvar, reportar, BASE_URL 8 | 9 | qt_bytes = 0 10 | qt_arqs = 0 11 | conj_baixar = set() 12 | 13 | def baixar_uma(nome, numero): 14 | global qt_bytes, qt_arqs 15 | url = BASE_URL+nome 16 | with contextlib.closing(urllib2.urlopen(url)) as img_orig: 17 | img = img_orig.read() 18 | qt_bytes += salvar(nome, img) 19 | qt_arqs += 1 20 | print '\t\t\t%3d\t%s --> salvo' % (numero, nome) 21 | conj_baixar.discard(nome) 22 | 23 | # GNU/Linux e Mac OSX suportam poucas centenas de threads 24 | MAX_THREADS = 100 25 | 26 | def baixar(qtd): 27 | """ busca e salva a quantidade ``qtd`` de bandeiras """ 28 | 29 | assert qtd <= MAX_THREADS, 'limite: %s downloads paralelos' % MAX_THREADS 30 | for num, sigla in enumerate(ler_siglas(qtd), 1): 31 | # baixar bandeiras com inicial 'a' ou 'b' 32 | nome = sigla + '-lgflag.gif' 33 | print '\t%3d\t%s' % (num, nome) 34 | tarefa = threading.Thread(target=baixar_uma, args=(nome, num)) 35 | tarefa.start() 36 | conj_baixar.add(nome) 37 | 38 | while conj_baixar: 39 | pass 40 | 41 | return qt_bytes, qt_arqs 42 | 43 | if __name__=='__main__': 44 | reportar(baixar) 45 | 46 | """ 47 | $ python sincrono_threads.py 3 48 | baixando 3 arquivos... 49 | 1 aa-lgflag.gif 50 | 2 ac-lgflag.gif 51 | 3 ae-lgflag.gif 52 | 1 aa-lgflag.gif --> salvo 53 | 2 ac-lgflag.gif --> salvo 54 | 3 ae-lgflag.gif --> salvo 55 | 11889 bytes baixados em 3 arquivos 56 | tempo transcorrido: 1.08s 57 | """ 58 | -------------------------------------------------------------------------------- /async/threads_queue.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | import contextlib 4 | import urllib2 5 | import threading 6 | from Queue import Queue 7 | 8 | from utilflags import ler_siglas, salvar, reportar, BASE_URL 9 | 10 | qt_bytes = 0 11 | qt_arqs = 0 12 | fila = Queue() 13 | 14 | def baixar_uma(nome, numero): 15 | global qt_bytes, qt_arqs 16 | url = BASE_URL+nome 17 | with contextlib.closing(urllib2.urlopen(url)) as img_orig: 18 | img = img_orig.read() 19 | qt_bytes += salvar(nome, img) 20 | qt_arqs += 1 21 | print '\t\t\t%3d\t%s --> salvo' % (numero, nome) 22 | 23 | NUM_THREADS = 10 24 | 25 | def worker(): 26 | while True: 27 | nome, numero = fila.get() 28 | baixar_uma(nome, numero) 29 | fila.task_done() 30 | 31 | def baixar(qtd): 32 | """ busca e salva a quantidade ``qtd`` de bandeiras """ 33 | 34 | # criar threads 35 | for i in range(NUM_THREADS): 36 | tarefa = threading.Thread(target=worker) 37 | tarefa.daemon = True 38 | tarefa.start() 39 | 40 | # enfileirar tarefas 41 | for numero, sigla in enumerate(ler_siglas(qtd), 1): 42 | # baixar bandeiras com inicial 'a' ou 'b' 43 | nome = sigla + '-lgflag.gif' 44 | print '\t%3d\t%s' % (numero, nome) 45 | fila.put((nome, numero)) 46 | 47 | fila.join() 48 | 49 | return qt_bytes, qt_arqs 50 | 51 | if __name__=='__main__': 52 | reportar(baixar) 53 | 54 | """ 55 | $ python sincrono_queue.py 3 56 | baixando 3 arquivos... 57 | 1 aa-lgflag.gif 58 | 2 ac-lgflag.gif 59 | 3 ae-lgflag.gif 60 | 2 ac-lgflag.gif --> salvo 61 | 1 aa-lgflag.gif --> salvo 62 | 3 ae-lgflag.gif --> salvo 63 | 11889 bytes baixados em 3 arquivos 64 | tempo transcorrido: 0.93s 65 | 66 | """ 67 | -------------------------------------------------------------------------------- /async/utilflags.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | import time 4 | import os 5 | import shutil 6 | import sys 7 | 8 | # URL onde ficam as bandeiras originais 9 | 10 | BASE_URL = ('https://www.cia.gov/library/publications/' 11 | 'the-world-factbook/graphics/flags/large/') 12 | 13 | # Apache Local em lontra (Mac OS X) 14 | #BASE_URL = 'http://localhost/~luciano/cia/flags/CIA_Flags_of_the_World_files/' 15 | 16 | # $ cd ~/prj/oturing/ppqsp/async/flags/CIA_Flags_of_the_World_files 17 | # $ python -m SimpleHTTPServer 8000 18 | #BASE_URL = 'http://localhost:8000/' 19 | 20 | DIR_DESTINO = './bandeiras/' # onde serão salvas as bandeiras 21 | 22 | ARQ_SIGLAS = 'siglas.txt' # arquivo que contem as siglas dos paises 23 | 24 | def recriar_diretorio(): 25 | """ apaga e recria diretório de destino """ 26 | try: 27 | shutil.rmtree(DIR_DESTINO) 28 | except OSError: 29 | pass 30 | os.mkdir(DIR_DESTINO) 31 | 32 | def ler_siglas(qtd_max=None): 33 | """ lê siglas de bandeiras do arquivo, devolve lista """ 34 | with open(ARQ_SIGLAS) as arq: 35 | siglas = arq.read().split() 36 | return siglas if qtd_max is None else siglas[:qtd_max] 37 | 38 | def salvar(nome, carga): 39 | """ salva o arquivo remoto localmente, devolve numero de bytes salvos """ 40 | with open(DIR_DESTINO+nome, 'wb') as arq_local: 41 | arq_local.write(carga) 42 | return len(carga) 43 | 44 | def reportar(funcao_baixar): 45 | if len(sys.argv) == 2: 46 | qt_baixar = int(sys.argv[1]) 47 | else: 48 | qt_baixar = 10 49 | recriar_diretorio() 50 | print 'baixando %s arquivos...' % qt_baixar 51 | t0 = time.time() 52 | qt_bytes, qt_arqs = funcao_baixar(qt_baixar) 53 | print qt_bytes, 'bytes baixados em %s arquivos' % qt_arqs 54 | print 'tempo transcorrido: %0.2fs' % (time.time()-t0) 55 | -------------------------------------------------------------------------------- /atributos/atrib_dinamicos.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | '''Exemplo de acesso e atribuição dinâmica de atributos de instância. 5 | 6 | >>> n = Nova() 7 | * self.__setattr__('b') 8 | >>> print repr(n.a) 9 | 1 10 | >>> print repr(n.b) 11 | 2 12 | >>> print repr(n.c) 13 | * self.__getattr__('c') 14 | 'c?' 15 | >>> n.a = 10 16 | * self.__setattr__('a') 17 | >>> print repr(n.a) 18 | 10 19 | >>> n.x = 99 20 | * self.__setattr__('x') 21 | >>> print repr(n.x) 22 | 99 23 | 24 | ''' 25 | 26 | class Nova(object): 27 | a = 1 28 | 29 | def __init__(self): 30 | self.b = 2 31 | 32 | def __getattr__(self, nome): 33 | print '* self.__getattr__(%r)' % nome 34 | return nome + '?' 35 | 36 | def __setattr__(self, nome, valor): 37 | print '* self.__setattr__(%r)' % nome 38 | self.__dict__[nome] = valor 39 | 40 | if __name__=='__main__': 41 | import doctest 42 | doctest.testmod() 43 | -------------------------------------------------------------------------------- /atributos/descr_leitura.py: -------------------------------------------------------------------------------- 1 | ''' 2 | >>> o = C(7) 3 | >>> o.x 4 | 7 5 | >>> o.x = 8 6 | Traceback (most recent call last): 7 | ... 8 | AttributeError: atributo somente para leitura 9 | 10 | ''' 11 | 12 | class SoLeitura(object): 13 | def __init__(self, nome_atr): 14 | self.nome_atr = nome_atr 15 | def __get__(self, instance, owner): 16 | return getattr(instance, self.nome_atr) 17 | def __set__(self, instance, value): 18 | raise AttributeError('atributo somente para leitura') 19 | 20 | class C(object): 21 | def __init__(self, x): 22 | self._x = x 23 | x = SoLeitura('_x') 24 | -------------------------------------------------------------------------------- /atributos/descr_leitura2.py: -------------------------------------------------------------------------------- 1 | ''' 2 | 3 | >>> o = C(7, 3) 4 | >>> o.x 5 | 7 6 | >>> o.y 7 | 3 8 | >>> o.x = 8 9 | Traceback (most recent call last): 10 | ... 11 | AttributeError: atributo somente para leitura 12 | 13 | ''' 14 | 15 | class SoLeitura(object): 16 | def __init__(self, nome_atr): 17 | self.nome_atr = nome_atr 18 | def __get__(self, instance, owner): 19 | if (self.nome_atr.startswith('__') and 20 | not self.nome_atr.endswith('__')): 21 | prefixo = '_' + owner.__name__ 22 | else: 23 | prefixo = '' 24 | return getattr(instance, prefixo+self.nome_atr) 25 | def __set__(self, instance, value): 26 | raise AttributeError('atributo somente para leitura') 27 | 28 | class C(object): 29 | def __init__(self, x, y): 30 | self.__x = x 31 | self._y = y 32 | x = SoLeitura('__x') 33 | y = SoLeitura('_y') -------------------------------------------------------------------------------- /atributos/descr_natural.py: -------------------------------------------------------------------------------- 1 | ''' 2 | >>> o = C(7) 3 | >>> o.x 4 | 7 5 | >>> o._x 6 | 7 7 | >>> o.x = 0 8 | Traceback (most recent call last): 9 | ... 10 | TypeError: valor deve ser >= 1 11 | >>> o = C(-3) 12 | Traceback (most recent call last): 13 | ... 14 | TypeError: valor deve ser >= 1 15 | >>> class D(object): 16 | ... def __init__(self, x): 17 | ... self.x = x 18 | ... x = Natural('x', True) 19 | >>> u = D(0) 20 | >>> u.x 21 | 0 22 | 23 | ''' 24 | 25 | class Natural(object): 26 | def __init__(self, nome_atr, inclui_zero=False): 27 | self.nome_atr = nome_atr 28 | self.minimo = 0 if inclui_zero else 1 29 | def __get__(self, instance, owner): 30 | return getattr(instance, '_'+self.nome_atr) 31 | def __set__(self, instance, value): 32 | if value >= self.minimo: 33 | setattr(instance, '_'+self.nome_atr, int(value)) 34 | else: 35 | msg = 'valor deve ser >= %s' 36 | raise TypeError(msg % self.minimo) 37 | 38 | class C(object): 39 | def __init__(self, x): 40 | self.x = x 41 | x = Natural('x') 42 | -------------------------------------------------------------------------------- /atributos/descr_quantidade.py: -------------------------------------------------------------------------------- 1 | ''' 2 | >>> o = C(7) 3 | >>> o.x 4 | 7 5 | >>> o._qtd_x 6 | 7 7 | >>> o.x = -1 8 | Traceback (most recent call last): 9 | ... 10 | TypeError: quantidade < 0 11 | >>> o.x 12 | 7 13 | 14 | ''' 15 | 16 | class Quantidade(object): 17 | def __init__(self, nome_atr): 18 | self.nome_atr = nome_atr 19 | def __get__(self, instance, owner): 20 | return getattr(instance, '_qtd_'+self.nome_atr) 21 | def __set__(self, instance, value): 22 | value = int(value) 23 | if value >= 0: 24 | setattr(instance, '_qtd_'+self.nome_atr, value) 25 | else: 26 | raise TypeError('quantidade < 0') 27 | 28 | class C(object): 29 | def __init__(self, x): 30 | self.x = x 31 | x = Quantidade('x') 32 | -------------------------------------------------------------------------------- /atributos/descritores.py: -------------------------------------------------------------------------------- 1 | class Quantidade(object): 2 | def __init__(self): 3 | self.nome_atr = self.__class__.__name__.lower()+str(id(self)) 4 | def __set__(self, instance, valor): 5 | if valor < 1: 6 | raise TypeError('quantidade deve ser > 0') 7 | else: 8 | setattr(instance, '__'+self.nome_atr, valor) 9 | def __get__(self, instance, owner): 10 | nome_atr_real = '__'+self.nome_atr 11 | return getattr(instance, nome_atr_real) 12 | -------------------------------------------------------------------------------- /atributos/exercicios/aluno.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | """ 4 | (1) Neste exemplo temos uma classe `Aluno` que é inicializada com um nome 5 | e uma data de nascimento em formato ISO-8601. O atributo `nascimento` é 6 | uma property ou descritor que armazena e devolve um objeto `datetime.date`:: 7 | 8 | >>> a = Aluno('Juca', '2000-06-10') 9 | >>> a.nome 10 | 'Juca' 11 | >>> a.nascimento 12 | datetime.date(2000, 6, 10) 13 | 14 | (2) Além da propriedade read/write `nascimento`, instâncias de aluno têm uma 15 | propriedade read-only chamada `idade` que devolve o número de anos completos 16 | desde o nascimento até hoje. Para implementar esta propriedade, usamos a 17 | função `idade` do módulo `idade.py` presente neste diretório. 18 | 19 | A seguir, testamos a função `idade.idade`, como se hoje fosse o dia 20 | 20/6/2010:: 21 | 22 | >>> idade(date(2009,6,20)) 23 | 1 24 | 25 | Como hoje não é 20/6/2010, o exemplo acima funciona devido a um patch 26 | explicado na função `test`. 27 | 28 | (3) Graças a este truque, podemos testar a propriedade `idade` do aluno como 29 | se estivéssemos em 20/6/2010:: 30 | 31 | >>> a.idade 32 | 10 33 | 34 | """ 35 | 36 | from datetime import datetime, date 37 | from idade import idade 38 | 39 | class Aluno(object): 40 | def __init__(self, nome, nascimento): 41 | self.nome = nome 42 | self.nascimento = nascimento 43 | 44 | def test(): 45 | """Para testar a idade, fazemos um patch no ambiente global do 46 | interpretador Python antes de executar os testes, substituindo a 47 | função `idade` importada do módulo `idade` por outra função que 48 | considera que hoje é sempre 20/6/2010. Veja como isso é feito na 49 | função `test`. 50 | """ 51 | import doctest 52 | idade_real = idade 53 | def idade_fake(nasc): 54 | return idade_real(nasc, date(2010,6,20)) 55 | globals()['idade'] = idade_fake # patch no ambiente global 56 | doctest.testmod(optionflags=doctest.REPORT_ONLY_FIRST_FAILURE) 57 | globals()['idade'] = idade_real # remover patch 58 | 59 | if __name__=='__main__': 60 | test() 61 | -------------------------------------------------------------------------------- /atributos/exercicios/contato.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | """ 4 | (1) Neste exemplo temos uma classe `Contato` que é inicializada com um 5 | nome e um e-mail:: 6 | 7 | >>> c = Contato('Juca', 'juca@lab.tmp.br') 8 | >>> c.nome 9 | 'Juca' 10 | >>> c.email 11 | 'juca@lab.tmp.br' 12 | 13 | 14 | (2) O atributo `email` é uma property ou descritor que aceita apenas 15 | e-mails válidos:: 16 | 17 | >>> c.email = 'x' 18 | Traceback (most recent call last): 19 | ... 20 | ValueError: e-mail invalido 'x' 21 | 22 | (3) A validação ocorre também ao instanciar um novo 'Contato':: 23 | 24 | >>> c = Contato('Yoli', 'y@y') 25 | Traceback (most recent call last): 26 | ... 27 | ValueError: e-mail invalido 'y@y' 28 | 29 | """ 30 | 31 | from email import is_valid 32 | 33 | class Contato(object): 34 | def __init__(self, nome, email): 35 | self.nome = nome 36 | self.email = email 37 | 38 | def test(): 39 | import doctest 40 | doctest.testmod(optionflags=doctest.REPORT_ONLY_FIRST_FAILURE) 41 | 42 | if __name__=='__main__': 43 | test() 44 | -------------------------------------------------------------------------------- /atributos/exercicios/email.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | E-mail validation regex from Django 1.3.1: 4 | 5 | http://code.djangoproject.com/svn/django/branches/releases/1.3.X/django/core/validators.py 6 | 7 | >>> is_valid('luciano@ramalho.org') 8 | True 9 | >>> is_valid('a@b.cd') 10 | True 11 | >>> is_valid('x') 12 | False 13 | 14 | """ 15 | 16 | import re 17 | 18 | email_re = re.compile( 19 | r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom 20 | r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string 21 | r')@(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$', re.IGNORECASE) # domain 22 | 23 | def is_valid(email): 24 | return bool(email_re.match(email)) 25 | -------------------------------------------------------------------------------- /atributos/exercicios/idade.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | """ 4 | >>> idade(date(2000, 1, 1), date(2000, 1, 1)) 5 | 0 6 | >>> idade(date(2000, 1, 1), date(2001, 1, 1)) 7 | 1 8 | >>> idade(date(2000, 1, 1), date(2001, 12, 31)) 9 | 1 10 | >>> idade(date(2000, 1, 1), date(2002, 1, 1)) 11 | 2 12 | >>> idade(date(2000, 2, 28), date(2001, 2, 28)) 13 | 1 14 | >>> idade(date(2000, 2, 28), date(2001, 2, 27)) 15 | 0 16 | >>> idade(date(2000, 2, 28), date(2001, 3, 1)) 17 | 1 18 | >>> idade(date(2000, 2, 28), date(2004, 2, 29)) 19 | 4 20 | >>> idade(date(2000, 2, 29), date(2001, 2, 28)) 21 | 0 22 | >>> idade(date(2000, 2, 29), date(2001, 3, 1)) 23 | 1 24 | >>> idade(date(2000, 2, 29), date(2004, 2, 29)) 25 | 4 26 | """ 27 | 28 | from datetime import date 29 | 30 | def idade(nascimento, hoje=None): # mudar o hoje é util para testar 31 | hoje = hoje or date.today() 32 | try: 33 | niver = nascimento.replace(year=hoje.year) 34 | except ValueError: 35 | # acontece qd. nascimento = 29/fev e ano atual não é bissexto 36 | niver = date(hoje.year, 3, 1) 37 | anos = hoje.year - nascimento.year 38 | return anos if niver <= hoje else anos - 1 39 | -------------------------------------------------------------------------------- /atributos/exercicios/jsobject.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | """ 4 | 5 | (1) Instâncias de `JSObj` imitam o comportamento de objetos JavaScript. 6 | Você pode criar uma instância e pendurar nela os atributos que quiser, 7 | como em Python:: 8 | 9 | >>> o = JSObj() 10 | >>> o.num = 10 11 | >>> o.num 12 | 10 13 | 14 | (2) Porém, diferente de objetos Python comuns, os atributos de uma 15 | instância de `JSObj` podem ser acessados como se ela fosse um dicionário:: 16 | 17 | >>> o['num'] 18 | 10 19 | 20 | (3) Além disso, atributos podem ser modificados usando a mesma notação:: 21 | 22 | >>> o['num'] = 13 23 | >>> o.num 24 | 13 25 | 26 | (4) Em JavaScript, novos atributos podem ser criados usando as duas 27 | notações (`.` e `[]`), mas neste exercício vamos impedir a criação de 28 | novos atributos via notação de `[]`: 29 | 30 | >>> o['nome'] = 'Lara' 31 | Traceback (most recent call last): 32 | ... 33 | TypeError: attributes can only be created using .dot notation 34 | 35 | (5) A função `len` pode ser usada para determinar o número de atributos 36 | de um `JSObj`:: 37 | 38 | >>> len(o) 39 | 1 40 | 41 | (6) Um `JSObj` pode ser construído a partir de um dicionário:: 42 | 43 | >>> sp = JSObj({'lat': 23.55, 'long': 46.63}) 44 | >>> sp.lat, sp.long 45 | (23.55, 46.63) 46 | 47 | (7) O construtor também pode ser invocado com argumentos nomeados:: 48 | 49 | >>> contato = JSObj(nome='Fred', fone='4321-1234') 50 | 51 | Imitar o comportamento de um `dict` permite aproveitar melhor o operador 52 | de formatação de strings `%`: 53 | 54 | >>> '%(nome)s: %(fone)s' % contato 55 | 'Fred: 4321-1234' 56 | 57 | (8) A representação de um `JSObj` imita uma invocação do construtor, 58 | permitindo a reconstrução do objeto via `eval`:: 59 | 60 | >>> o 61 | JSObj({'num': 13}) 62 | 63 | (9) O operador `==` é sobrecarregado para comparar os atributos de dois 64 | `JSObj`:: 65 | 66 | >>> sp == JSObj(lat=23.55, long=46.63) 67 | True 68 | 69 | Implementamos o `==` para poder testar se o `repr` realmente funciona 70 | com `eval`, como prometido no passo (8):: 71 | 72 | >>> sp == eval(repr(sp)) 73 | True 74 | 75 | """ 76 | 77 | class JSObj(object): 78 | """Uma classe que imita objetos JavaScript""" 79 | 80 | def test(): 81 | import doctest 82 | doctest.testmod(optionflags=doctest.REPORT_ONLY_FIRST_FAILURE) 83 | 84 | if __name__=='__main__': 85 | test() 86 | -------------------------------------------------------------------------------- /atributos/exercicios/mod11.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | import string 4 | 5 | def mod11(digitos): 6 | digitos = reversed([int(d) for d in str(digitos) if d in string.digits]) 7 | soma = sum((mult+2)*digito for mult, digito in enumerate(digitos)) 8 | dv = (11 - soma % 11) 9 | return str(dv) if dv < 10 else '0' 10 | 11 | def mod11_cpf(digitos): 12 | dv1 = mod11(digitos) 13 | dv2 = mod11(digitos+dv1) 14 | return dv1+dv2 15 | 16 | def cpf_valido(digitos): 17 | digitos = ''.join([d for d in str(digitos) if d in string.digits]) 18 | if len(digitos) != 11: 19 | return False 20 | dv = mod11_cpf(digitos[:-2]) 21 | return dv == digitos[-2:] 22 | 23 | def testes(): 24 | # CPFs de deputados listados em um processo publicado na Web 25 | cpfs = '''102.700.605-10 216.307.552-49 242.544.011-91 568.755.847-00 26 | 006.375.133-04 348.780.507-30 244.884.451-87 254.052.509-10 27 | 030.880.653-00 117.703.681-91 825.025.018-49 28 | 030.166.509-59'''.split() 29 | 30 | for cpf in cpfs: 31 | assert cpf_valido(cpf) 32 | print cpf, mod11_cpf(cpf[:-2]), cpf_valido(cpf) 33 | 34 | for i in range(10): 35 | s = str(i)*9 36 | print s, mod11_cpf(s) 37 | 38 | s = '012345678' 39 | print s, mod11_cpf(s) 40 | s = s[::-1] 41 | print s, mod11_cpf(s) 42 | s = '123456789' 43 | print s, mod11_cpf(s) 44 | s = s[::-1] 45 | print s, mod11_cpf(s) 46 | s = '123454321' 47 | print s, mod11_cpf(s) 48 | s = '010101010' 49 | print s, mod11_cpf(s) 50 | s = '101010101' 51 | print s, mod11_cpf(s) 52 | 53 | if __name__=='__main__': 54 | testes() -------------------------------------------------------------------------------- /atributos/gato.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | 4 | """ 5 | Registro de gato em um Pet Shop:: 6 | 7 | >>> felix = Gato('Felix') 8 | >>> felix.nome 9 | 'Felix' 10 | >>> felix.idade 11 | 0 12 | >>> print felix 13 | Felix (0) 14 | 15 | Note: até aqui, ``idade`` é um atributo da classe ``Gato``:: 16 | 17 | >>> Gato.idade 18 | 0 19 | 20 | Agora vamos atribuir uma ``idade`` a Felix:: 21 | 22 | >>> felix.idade = 5 23 | >>> print felix 24 | Felix (5) 25 | 26 | Isso não muda a ``idade`` da classe:: 27 | 28 | >>> Gato.idade 29 | 0 30 | 31 | 32 | """ 33 | 34 | class Gato(object): 35 | 36 | idade = 0 37 | 38 | def __init__(self, nome): 39 | self.nome = nome 40 | 41 | def __str__(self): 42 | return '%s (%s)' % (self.nome, self.idade) 43 | -------------------------------------------------------------------------------- /atributos/gato_v2.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | 4 | """ 5 | Registro de gato em um Pet Shop:: 6 | 7 | >>> felix = Gato('Felix') 8 | >>> felix.nome 9 | 'Felix' 10 | >>> felix.idade 11 | 0 12 | >>> print felix 13 | Felix (0) 14 | 15 | Agora vamos tentar atribuir uma ``idade`` a Felix:: 16 | 17 | >>> felix.idade = 5 18 | Traceback (most recent call last): 19 | ... 20 | AttributeError: can't set attribute 21 | 22 | 23 | Todo gato tem uma data de nascimento, cujo valor default é a data da 24 | instanciação do objeto (neste caso, hoje):: 25 | 26 | >>> felix.dt_nasc == date.today() 27 | True 28 | 29 | Se a data de nascimento não for hoje, a idade pode ser maior que zero:: 30 | 31 | >>> tom = Gato('Tom', date(1940, 4, 13)) 32 | >>> tom.idade >= 73 33 | True 34 | 35 | 36 | """ 37 | 38 | from datetime import date 39 | import idade 40 | 41 | class Gato(object): 42 | 43 | def __init__(self, nome, dt_nasc = date.today()): 44 | self.nome = nome 45 | self.dt_nasc = dt_nasc 46 | 47 | def __str__(self): 48 | return '%s (%s)' % (self.nome, self.idade) 49 | 50 | @property 51 | def idade(self): 52 | return idade.idade(self.dt_nasc) 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /atributos/granel/pedido.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | """ 4 | 5 | >>> passa = ItemPedido('uva passa', .5, 7.) 6 | >>> passa.preco 7 | 7.0 8 | >>> passa.subtotal() 9 | 3.5 10 | >>> passa.peso = -1 # problema!!! 11 | >>> passa.subtotal() # agora o comerciante deve R$7 para o freguês... 12 | -7.0 13 | 14 | 15 | """ 16 | 17 | 18 | 19 | class ItemPedido(object): 20 | 21 | def __init__(self, descricao, peso, preco): 22 | self.descricao = descricao 23 | self.peso = peso 24 | self.preco = preco 25 | 26 | def subtotal(self): 27 | return self.peso * self.preco 28 | -------------------------------------------------------------------------------- /atributos/granel/pedido_java.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | """ 4 | 5 | >>> passa = ItemPedido('uva passa', .5, 7.) 6 | >>> passa.preco 7 | 7.0 8 | >>> passa.subtotal() 9 | 3.5 10 | >>> passa.set_peso(10) 11 | >>> passa.get_peso() 12 | 10 13 | >>> passa.subtotal() 14 | 70.0 15 | >>> passa.set_peso(-1) 16 | Traceback (most recent call last): 17 | ... 18 | ValueError: valor deve ser > 0 19 | >>> passa.__peso # violação de encapsulamento??? 20 | Traceback (most recent call last): 21 | ... 22 | AttributeError: 'ItemPedido' object has no attribute '__peso' 23 | 24 | """ 25 | 26 | 27 | 28 | class ItemPedido(object): 29 | 30 | def __init__(self, descricao, peso, preco): 31 | self.descricao = descricao 32 | self.set_peso(peso) 33 | self.preco = preco 34 | 35 | def get_peso(self): 36 | return self.__peso 37 | 38 | def set_peso(self, valor): 39 | if valor > 0: 40 | self.__peso = valor 41 | else: 42 | raise ValueError('valor deve ser > 0') 43 | 44 | def subtotal(self): 45 | return self.get_peso() * self.preco 46 | -------------------------------------------------------------------------------- /atributos/granel/pedido_v2.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | """ 4 | 5 | >>> passa = ItemPedido('uva passa', .5, 7.) 6 | >>> passa.preco 7 | 7.0 8 | >>> passa.subtotal() 9 | 3.5 10 | >>> passa.peso = 10 11 | >>> passa.peso 12 | 10 13 | >>> passa.subtotal() 14 | 70.0 15 | >>> passa.peso = -1 16 | Traceback (most recent call last): 17 | ... 18 | ValueError: valor deve ser > 0 19 | >>> passa.__peso # violação de encapsulamento??? 20 | Traceback (most recent call last): 21 | ... 22 | AttributeError: 'ItemPedido' object has no attribute '__peso' 23 | 24 | """ 25 | 26 | 27 | class ItemPedido(object): 28 | 29 | def __init__(self, descricao, peso, preco): 30 | self.descricao = descricao 31 | self.peso = peso 32 | self.preco = preco 33 | 34 | @property 35 | def peso(self): 36 | return self.__peso 37 | 38 | @peso.setter 39 | def peso(self, valor): 40 | if valor > 0: 41 | self.__peso = valor 42 | else: 43 | raise ValueError('valor deve ser > 0') 44 | 45 | def subtotal(self): 46 | return self.peso * self.preco 47 | -------------------------------------------------------------------------------- /atributos/idade.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | """ 5 | Cálculos de idade:: 6 | 7 | >>> hoje = date(2009, 2, 28) 8 | >>> idade(date(2008, 2, 28), hoje) 9 | 1 10 | >>> idade(date(2008, 2, 29), hoje) 11 | 0 12 | >>> idade(date(2000, 1, 1), hoje) 13 | 9 14 | 15 | Idades com meses:: 16 | 17 | >>> nasc = date(2000, 5, 10) 18 | >>> idade_meses(nasc, date(2001, 5, 10)) 19 | (1, 0) 20 | >>> idade_meses(nasc, date(2001, 9, 10)) 21 | (1, 4) 22 | >>> idade_meses(nasc, date(2001, 9, 9)) 23 | (1, 3) 24 | >>> idade_meses(nasc, date(2001, 4, 10)) 25 | (0, 11) 26 | >>> idade_meses(nasc, date(2001, 4, 9)) 27 | (0, 10) 28 | 29 | """ 30 | 31 | from datetime import date 32 | 33 | def idade(nascimento, quando=None): 34 | if quando is None: 35 | quando = date.today() 36 | anos = quando.year - nascimento.year 37 | if (nascimento.month, nascimento.day) > (quando.month, quando.day): 38 | anos -= 1 39 | return anos 40 | 41 | def idade_meses(nascimento, quando=None): 42 | if quando is None: 43 | quando = date.today() 44 | anos = idade(nascimento, quando) 45 | meses = quando.month - nascimento.month 46 | if nascimento.day > quando.day: 47 | meses -= 1 48 | if meses < 0: 49 | meses = 12 + meses 50 | return (anos, meses) 51 | 52 | 53 | -------------------------------------------------------------------------------- /atributos/java/AcessaPrivado.java: -------------------------------------------------------------------------------- 1 | import java.lang.reflect.Field; 2 | 3 | public class AcessaPrivado { 4 | 5 | public static void main(String[] args) { 6 | ObjetoSecreto oSecreto = new ObjetoSecreto("senha super secreta"); 7 | Field campoPrivado = null; 8 | try { 9 | campoPrivado = ObjetoSecreto.class.getDeclaredField("escondido"); 10 | } 11 | catch (NoSuchFieldException e) { 12 | System.err.println(e); 13 | System.exit(1); 14 | } 15 | campoPrivado.setAccessible(true); // arrombamos a porta 16 | try { 17 | String tavaEscondido = (String) campoPrivado.get(oSecreto); 18 | System.out.println("oSecreto.escondido = " + tavaEscondido); 19 | } 20 | catch (IllegalAccessException e) { 21 | // esta exceção nao acontece porque fizemos setAcessible(true) 22 | System.err.println(e); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /atributos/java/AcessaPrivado.py: -------------------------------------------------------------------------------- 1 | import ObjetoSecreto 2 | 3 | oSecreto = ObjetoSecreto('senha super secreta') 4 | campoPrivado = ObjetoSecreto.getDeclaredField('escondido') 5 | campoPrivado.setAccessible(True) # arrombamos a porta 6 | print 'oSecreto.escondido =', campoPrivado.get(oSecreto) 7 | -------------------------------------------------------------------------------- /atributos/java/ListaPrivados.java: -------------------------------------------------------------------------------- 1 | import java.lang.reflect.Field; 2 | import java.lang.reflect.Modifier; 3 | 4 | public class ListaPrivados { 5 | 6 | public static void main(String[] args) { 7 | ObjetoSecreto oSecreto = new ObjetoSecreto("senha super secreta"); 8 | Field campos[] = ObjetoSecreto.class.getDeclaredFields(); 9 | for (Field campo : campos) 10 | if (Modifier.isPrivate(campo.getModifiers())) { // só campos privados! 11 | System.out.println(campo.toString()); 12 | campo.setAccessible(true); // arrombamos a porta 13 | try { 14 | String valor = (String) campo.get(oSecreto); 15 | System.out.println("\t" + campo.getName() + " = " + valor); 16 | } 17 | catch (IllegalAccessException e) { 18 | // esta exceção nao acontece porque fizemos setAcessible(true) 19 | System.err.println(e); 20 | System.exit(1); 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /atributos/java/ListaPrivados.py: -------------------------------------------------------------------------------- 1 | from java.lang.reflect import Modifier 2 | import ObjetoSecreto 3 | 4 | oSecreto = ObjetoSecreto('senha super secreta') 5 | campos = ObjetoSecreto.getDeclaredFields() 6 | for campo in campos: 7 | if Modifier.isPrivate(campo.getModifiers()): # so campos privados! 8 | print campo 9 | campo.setAccessible(True) # arrombamos a porta 10 | print '\t', campo.getName(), '=', campo.get(oSecreto) 11 | -------------------------------------------------------------------------------- /atributos/java/MudaPrivado.java: -------------------------------------------------------------------------------- 1 | import java.lang.reflect.Field; 2 | 3 | public class MudaPrivado { 4 | 5 | public static void main(String[] args) { 6 | ObjetoSecreto oSecreto = new ObjetoSecreto("nada"); 7 | Field campoPrivado = null; 8 | try { 9 | campoPrivado = ObjetoSecreto.class.getDeclaredField("oculto"); 10 | } 11 | catch (NoSuchFieldException e) { 12 | System.err.println(e); 13 | System.exit(1); 14 | } 15 | campoPrivado.setAccessible(true); // arrombamos a porta 16 | try { 17 | String tavaEscondido = (String) campoPrivado.get(oSecreto); 18 | System.out.println("oSecreto.oculto = " + tavaEscondido); 19 | campoPrivado.set(oSecreto, "novo segredo"); 20 | tavaEscondido = (String) campoPrivado.get(oSecreto); 21 | System.out.println("oSecreto.oculto = " + tavaEscondido); 22 | } 23 | catch (IllegalAccessException e) { 24 | // esta exceção nao acontece porque fizemos setAcessible(true) 25 | System.err.println(e); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /atributos/java/MudaPrivado.py: -------------------------------------------------------------------------------- 1 | import ObjetoSecreto 2 | 3 | oSecreto = ObjetoSecreto('nada') 4 | campoPrivado = ObjetoSecreto.getDeclaredField('oculto') 5 | campoPrivado.setAccessible(True) # arrombamos a porta 6 | print 'oSecreto.oculto =', campoPrivado.get(oSecreto) 7 | campoPrivado.set(oSecreto, 'novo segredo') 8 | print 'oSecreto.oculto =', campoPrivado.get(oSecreto) 9 | -------------------------------------------------------------------------------- /atributos/java/ObjetoSecreto.java: -------------------------------------------------------------------------------- 1 | public class ObjetoSecreto { 2 | 3 | private String escondido = ""; 4 | private String oculto = "dado ultra secreto"; 5 | 6 | public ObjetoSecreto(String texto) { 7 | this.escondido = texto; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /atributos/metaclasses/README: -------------------------------------------------------------------------------- 1 | Este diretorio apresenta a progressão de um exemplo desde o uso de uma 2 | simples property até a implementação de descritores e uma metaclasse 3 | para gerenciar e ordenar vários descritores. -------------------------------------------------------------------------------- /atributos/metaclasses/pedido0.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | """ 4 | Exemplo de uma classe com propriedades 5 | 6 | A classe ItemPedido deve ser instanciada com os dados essenciais que sao: 7 | descricao do item, preco unitario e quantidade. 8 | 9 | >>> bolas = ItemPedido('bola de golf', 2, 10) 10 | >>> bolas.descr 11 | 'bola de golf' 12 | >>> bolas.qtd 13 | 10 14 | 15 | O atributo qtd de um ItemPedido nunca pode ser < 1: 16 | 17 | >>> duendes = ItemPedido('duende verde', 2.99, 0) 18 | Traceback (most recent call last): 19 | ... 20 | TypeError: a quantidade deve ser >= 1 21 | >>> duendes = ItemPedido('duende verde', 2.99, 13) 22 | >>> duendes.qtd 23 | 13 24 | >>> duendes.qtd = -1 25 | Traceback (most recent call last): 26 | ... 27 | TypeError: a quantidade deve ser >= 1 28 | >>> duendes.qtd = 20 29 | >>> duendes.qtd 30 | 20 31 | 32 | 33 | """ 34 | 35 | class ItemPedido(object): 36 | """um item de um pedido""" 37 | def __init__(self, descr, pr_unitario, qtd): 38 | self.descr = descr 39 | self.pr_unitario = pr_unitario 40 | self.qtd = qtd 41 | 42 | @property 43 | def qtd(self): 44 | return self.__qtd 45 | 46 | @qtd.setter 47 | def qtd(self, qtd): 48 | if qtd < 1: 49 | raise TypeError('a quantidade deve ser >= 1') 50 | self.__qtd = qtd 51 | 52 | -------------------------------------------------------------------------------- /atributos/metaclasses/pedido1.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | """ 4 | Exemplo de uma classe com descritor 5 | 6 | A classe ItemPedido deve ser instanciada com os dados essenciais que sao: 7 | descricao do item, preco unitario e quantidade. 8 | 9 | >>> bolas = ItemPedido('bola de golf', 2, 10) 10 | >>> bolas.descr 11 | 'bola de golf' 12 | >>> bolas.qtd 13 | 10 14 | 15 | O atributo qtd de um ItemPedido nunca pode ser < 1: 16 | 17 | >>> duendes = ItemPedido('duende verde', 2.99, 0) 18 | Traceback (most recent call last): 19 | ... 20 | TypeError: quantidade deve ser > 0 21 | >>> duendes = ItemPedido('duende verde', 2.99, 13) 22 | >>> duendes.qtd 23 | 13 24 | >>> duendes.qtd = -1 25 | Traceback (most recent call last): 26 | ... 27 | TypeError: quantidade deve ser > 0 28 | >>> duendes.qtd = 20 29 | >>> duendes.qtd 30 | 20 31 | 32 | Se o argumento qtd for None, eh usado um valor default, definido 33 | na classe: 34 | 35 | >>> unicornio = ItemPedido('unicornio', 199000) 36 | >>> unicornio.qtd 37 | 1 38 | 39 | """ 40 | 41 | class Quantidade(object): 42 | def __init__(self, nome_atr): 43 | self.nome_atr = nome_atr 44 | def __set__(self, instance, valor): 45 | if valor < 1: 46 | raise TypeError('quantidade deve ser > 0') 47 | else: 48 | setattr(instance, '__'+self.nome_atr, valor) 49 | def __get__(self, instance, owner): 50 | nome_atr_real = '__'+self.nome_atr 51 | if hasattr(instance, nome_atr_real): 52 | return getattr(instance, nome_atr_real) 53 | else: 54 | return getattr(owner, self.nome_atr+'_default') 55 | 56 | 57 | class ItemPedido(object): 58 | """um item de um pedido""" 59 | 60 | qtd = Quantidade('qtd') 61 | qtd_default = 1 62 | 63 | def __init__(self, descr, pr_unitario, qtd=None): 64 | self.descr = descr 65 | if qtd is not None: 66 | self.qtd = qtd 67 | self.pr_unitario = pr_unitario 68 | -------------------------------------------------------------------------------- /atributos/metaclasses/pedido2.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | """ 4 | Exemplo de uma classe com descritores 5 | 6 | A classe ItemPedido deve ser instanciada com os dados essenciais que sao: 7 | descricao do item, preco unitario e quantidade. 8 | 9 | >>> bolas = ItemPedido('bola de golf', 2, 10) 10 | >>> bolas.descr 11 | 'bola de golf' 12 | >>> bolas.qtd 13 | 10 14 | 15 | O atributo qtd de um ItemPedido nunca pode ser <= 0: 16 | 17 | >>> duendes = ItemPedido('duende verde', 2.99, 0) 18 | Traceback (most recent call last): 19 | ... 20 | TypeError: quantidade deve ser > 0 21 | >>> duendes = ItemPedido('duende verde', 2.99, 13) 22 | >>> duendes.qtd 23 | 13 24 | >>> duendes.qtd = -1 25 | Traceback (most recent call last): 26 | ... 27 | TypeError: quantidade deve ser > 0 28 | >>> duendes.qtd = 20 29 | >>> duendes.qtd 30 | 20 31 | 32 | O preco também nao pode ser <= 0: 33 | 34 | >>> saci = ItemPedido('saci', -1, 0) 35 | Traceback (most recent call last): 36 | ... 37 | TypeError: quantidade deve ser > 0 38 | 39 | """ 40 | from descritores import Quantidade 41 | 42 | class ItemPedido(object): 43 | """um item de um pedido""" 44 | 45 | qtd = Quantidade() 46 | pr_unitario = Quantidade() 47 | 48 | def __init__(self, descr, pr_unitario, qtd): 49 | self.descr = descr 50 | self.qtd = qtd 51 | self.pr_unitario = pr_unitario 52 | -------------------------------------------------------------------------------- /atributos/metaclasses/pedido3.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | """ 4 | Exemplo de uma classe com descritores 5 | 6 | A classe ItemPedido deve ser instanciada com os dados essenciais que sao: 7 | descricao do item, preco unitario e quantidade. 8 | 9 | >>> bolas = ItemPedido('bola de golf', 2, 10) 10 | >>> bolas.descr 11 | 'bola de golf' 12 | >>> bolas.qtd 13 | 10 14 | 15 | O atributo qtd de um ItemPedido nunca pode ser <= 0: 16 | 17 | >>> duendes = ItemPedido('duende verde', 2.99, 0) 18 | Traceback (most recent call last): 19 | ... 20 | TypeError: qtd deve ser > 0 21 | >>> duendes = ItemPedido('duende verde', 2.99, 13) 22 | >>> duendes.qtd 23 | 13 24 | >>> duendes.qtd = -1 25 | Traceback (most recent call last): 26 | ... 27 | TypeError: qtd deve ser > 0 28 | >>> duendes.qtd = 20 29 | >>> duendes.qtd 30 | 20 31 | 32 | O preco também nao pode ser <= 0: 33 | 34 | >>> saci = ItemPedido('saci', -1, 10) 35 | Traceback (most recent call last): 36 | ... 37 | TypeError: pr_unitario deve ser > 0 38 | 39 | """ 40 | class Quantidade(object): 41 | def __set__(self, instance, valor): 42 | if not hasattr(self, 'nome_atr'): 43 | for nome, atr in instance.__class__.__dict__.items(): 44 | if atr is self: 45 | self.nome_atr = '__'+nome 46 | break 47 | else: # only if the for loop terminates without break 48 | assert False, 'descriptor not found in class' 49 | if valor < 1: 50 | raise TypeError('%s deve ser > 0' % self.nome_atr[2:]) 51 | setattr(instance, self.nome_atr, valor) 52 | 53 | def __get__(self, instance, owner): 54 | return getattr(instance, self.nome_atr) 55 | 56 | class ItemPedido(object): 57 | """um item de um pedido""" 58 | 59 | qtd = Quantidade() 60 | pr_unitario = Quantidade() 61 | 62 | def __init__(self, descr, pr_unitario, qtd): 63 | self.descr = descr 64 | self.qtd = qtd 65 | self.pr_unitario = pr_unitario 66 | -------------------------------------------------------------------------------- /atributos/metaclasses/pedido4.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | """ 4 | Exemplo de uma classe com descritores 5 | 6 | A classe ItemPedido deve ser instanciada com os dados essenciais que sao: 7 | descricao do item, preco unitario e quantidade. 8 | 9 | >>> bolas = ItemPedido('bola de golf', 2, 10) 10 | >>> bolas.descr 11 | 'bola de golf' 12 | >>> bolas.qtd 13 | 10 14 | 15 | O atributo qtd de um ItemPedido nunca pode ser <= 0: 16 | 17 | >>> duendes = ItemPedido('duende verde', 2.99, 0) 18 | Traceback (most recent call last): 19 | ... 20 | TypeError: qtd deve ser > 0 21 | >>> duendes = ItemPedido('duende verde', 2.99, 13) 22 | >>> duendes.qtd 23 | 13 24 | >>> duendes.qtd = -1 25 | Traceback (most recent call last): 26 | ... 27 | TypeError: qtd deve ser > 0 28 | >>> duendes.qtd = 20 29 | >>> duendes.qtd 30 | 20 31 | 32 | O preco também nao pode ser <= 0: 33 | 34 | >>> saci = ItemPedido('saci', -1, 10) 35 | Traceback (most recent call last): 36 | ... 37 | TypeError: pr_unitario deve ser > 0 38 | 39 | """ 40 | 41 | from abc import ABCMeta, abstractmethod 42 | 43 | class ValidatedDescriptor(object): 44 | __metaclass__ = ABCMeta 45 | 46 | @abstractmethod 47 | def validator(self, instance, value): 48 | """Return value or raise TypeError for invalid values 49 | 50 | This method is invoked by the __set__ method of the descriptor. 51 | Parameters are the same for __set__: self, instance, value. 52 | """ 53 | 54 | def __set__(self, instance, value): 55 | if not hasattr(self, 'attr_name'): 56 | for name, attr in instance.__class__.__dict__.items(): 57 | if attr is self: 58 | self.attr_name = name 59 | break 60 | else: # only if the for loop terminates without break 61 | assert False, 'descriptor not found in class' 62 | # template method pattern: delegar validacao para subclasses 63 | value = self.validator(instance, value) 64 | setattr(instance, '__'+self.attr_name, value) 65 | 66 | def __get__(self, instance, owner): 67 | return getattr(instance, '__'+self.attr_name) 68 | 69 | class Quantidade(ValidatedDescriptor): 70 | def validator(self, instance, value): 71 | if value < 1: 72 | raise ValueError('%s deve ser > 0' % self.attr_name) 73 | return value 74 | 75 | class ItemPedido(object): 76 | """um item de um pedido""" 77 | 78 | qtd = Quantidade() 79 | pr_unitario = Quantidade() 80 | 81 | def __init__(self, descr, pr_unitario, qtd): 82 | self.descr = descr 83 | self.qtd = qtd 84 | self.pr_unitario = pr_unitario 85 | -------------------------------------------------------------------------------- /atributos/metaclasses/pedido5.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | """ 4 | Exemplo de uma classe com descritores 5 | 6 | A classe ItemPedido deve ser instanciada com os dados essenciais que sao: 7 | descricao do item, preco unitario e quantidade. 8 | 9 | >>> bolas = ItemPedido('bola de golf', 2, 10) 10 | >>> bolas.descr 11 | 'bola de golf' 12 | >>> bolas.qtd 13 | 10 14 | 15 | O atributo qtd de um ItemPedido nunca pode ser <= 0: 16 | 17 | >>> duendes = ItemPedido('duende verde', 2.99, 0) 18 | Traceback (most recent call last): 19 | ... 20 | TypeError: qtd deve ser > 0 21 | >>> duendes = ItemPedido('duende verde', 2.99, 13) 22 | >>> duendes.qtd 23 | 13 24 | >>> duendes.qtd = -1 25 | Traceback (most recent call last): 26 | ... 27 | TypeError: qtd deve ser > 0 28 | >>> duendes.qtd = 20 29 | >>> duendes.qtd 30 | 20 31 | 32 | O preco também nao pode ser <= 0: 33 | 34 | >>> saci = ItemPedido('saci perere', -1, 10) 35 | Traceback (most recent call last): 36 | ... 37 | TypeError: pr_unitario deve ser > 0 38 | 39 | 40 | E a descricao deve ter pelo menos duas palavras: 41 | 42 | >>> saci = ItemPedido('saci', -1, 10) 43 | Traceback (most recent call last): 44 | ... 45 | TypeError: descr deve ter pelo menos 2 palavras 46 | 47 | 48 | Podemos obter a lista dos descritores de ItemPedido: 49 | 50 | >>> ItemPedido.listar_descritores() 51 | descr : Palavras 52 | pr_unitario : Quantidade 53 | qtd : Quantidade 54 | 55 | Mas os descritores não aparecem na ordem em que foram declarados. 56 | 57 | """ 58 | 59 | from abc import ABCMeta, abstractmethod 60 | 61 | class ValidatedDescriptor(object): 62 | __metaclass__ = ABCMeta 63 | 64 | @abstractmethod 65 | def validator(self, instance, value): 66 | """Return value or raise TypeError for invalid values 67 | 68 | This method is invoked by the __set__ method of the descriptor. 69 | Parameters are the same for __set__: self, instance, value. 70 | """ 71 | 72 | def __set__(self, instance, value): 73 | if not hasattr(self, 'attr_name'): 74 | for name, attr in instance.__class__.__dict__.items(): 75 | if attr is self: 76 | self.attr_name = name 77 | break 78 | else: # only if the for loop terminates without break 79 | assert False, 'descriptor not found in class' 80 | # template method pattern: delegar validacao para subclasses 81 | value = self.validator(instance, value) 82 | setattr(instance, '__'+self.attr_name, value) 83 | 84 | def __get__(self, instance, owner): 85 | return getattr(instance, '__'+self.attr_name) 86 | 87 | class Quantidade(ValidatedDescriptor): 88 | def validator(self, instance, value): 89 | value = int(value) 90 | if value < 1: 91 | raise TypeError('%s deve ser > 0' % self.attr_name) 92 | return value 93 | 94 | class Palavras(ValidatedDescriptor): 95 | def __init__(self, min_palavras): 96 | self.min_palavras = min_palavras 97 | 98 | def validator(self, instance, value): 99 | if len(value.split()) < self.min_palavras: 100 | msg = '%s deve ter pelo menos %s palavras' 101 | raise TypeError(msg % (self.attr_name, self.min_palavras)) 102 | return value 103 | 104 | class ItemPedido(object): 105 | """um item de um pedido""" 106 | 107 | qtd = Quantidade() 108 | descr = Palavras(2) 109 | pr_unitario = Quantidade() 110 | 111 | def __init__(self, descr, pr_unitario, qtd): 112 | self.descr = descr 113 | self.qtd = qtd 114 | self.pr_unitario = pr_unitario 115 | 116 | @classmethod 117 | def listar_descritores(cls): 118 | for nome, atr in cls.__dict__.items(): 119 | if isinstance(atr, ValidatedDescriptor): 120 | print '%12s : %s' % (nome, atr.__class__.__name__) 121 | 122 | -------------------------------------------------------------------------------- /atributos/metaclasses/pedido6.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | """ 4 | Exemplo de uma classe com descritores 5 | 6 | A classe ItemPedido deve ser instanciada com os dados essenciais que sao: 7 | descricao do item, preco unitario e quantidade. 8 | 9 | >>> bolas = ItemPedido('bola de golf', 2, 10) 10 | >>> bolas.descr 11 | 'bola de golf' 12 | >>> bolas.qtd 13 | 10 14 | 15 | O atributo qtd de um ItemPedido nunca pode ser <= 0: 16 | 17 | >>> duendes = ItemPedido('duende verde', 2.99, 0) 18 | Traceback (most recent call last): 19 | ... 20 | TypeError: qtd deve ser > 0 21 | >>> duendes = ItemPedido('duende verde', 2.99, 13) 22 | >>> duendes.qtd 23 | 13 24 | >>> duendes.qtd = -1 25 | Traceback (most recent call last): 26 | ... 27 | TypeError: qtd deve ser > 0 28 | >>> duendes.qtd = 20 29 | >>> duendes.qtd 30 | 20 31 | 32 | O preco também nao pode ser <= 0: 33 | 34 | >>> saci = ItemPedido('saci perere', -1, 10) 35 | Traceback (most recent call last): 36 | ... 37 | TypeError: pr_unitario deve ser > 0 38 | 39 | 40 | E a descricao deve ter pelo menos duas palavras: 41 | 42 | >>> saci = ItemPedido('saci', -1, 10) 43 | Traceback (most recent call last): 44 | ... 45 | TypeError: descr deve ter pelo menos 2 palavras 46 | 47 | 48 | Podemos obter a lista dos descritores de ItemPedido, na ordem em que 49 | foram declarados em ItemPedido: 50 | 51 | >>> ItemPedido.listar_descritores() 52 | qtd : Quantidade 53 | descr : Palavras 54 | pr_unitario : Quantidade 55 | 56 | 57 | """ 58 | 59 | from abc import ABCMeta, abstractmethod 60 | 61 | class ValidatedDescriptor(object): 62 | __metaclass__ = ABCMeta 63 | 64 | __instance_counter = 0 65 | 66 | def __new__(cls, *args): 67 | new_instance = super(ValidatedDescriptor, cls).__new__(cls, *args) 68 | new_instance._instance_index = ValidatedDescriptor.__instance_counter 69 | ValidatedDescriptor.__instance_counter += 1 70 | return new_instance 71 | 72 | @abstractmethod 73 | def validator(self, instance, value): 74 | """Return value or raise TypeError for invalid values 75 | 76 | This method is invoked by the __set__ method of the descriptor. 77 | Parameters are the same for __set__: self, instance, value. 78 | """ 79 | 80 | def __set__(self, instance, value): 81 | if not hasattr(self, 'attr_name'): 82 | for name, attr in instance.__class__.__dict__.items(): 83 | if attr is self: 84 | self.attr_name = name 85 | break 86 | else: # only if the for loop terminates without break 87 | assert False, 'descriptor not found in class' 88 | # template method pattern: delegar validacao para subclasses 89 | value = self.validator(instance, value) 90 | setattr(instance, '__'+self.attr_name, value) 91 | 92 | def __get__(self, instance, owner): 93 | return getattr(instance, '__'+self.attr_name) 94 | 95 | class Quantidade(ValidatedDescriptor): 96 | def validator(self, instance, value): 97 | value = int(value) 98 | if value < 1: 99 | raise TypeError('%s deve ser > 0' % self.attr_name) 100 | return value 101 | 102 | class Palavras(ValidatedDescriptor): 103 | def __init__(self, min_palavras): 104 | self.min_palavras = min_palavras 105 | 106 | def validator(self, instance, value): 107 | if len(value.split()) < self.min_palavras: 108 | msg = '%s deve ter pelo menos %s palavras' 109 | raise TypeError(msg % (self.attr_name, self.min_palavras)) 110 | return value 111 | 112 | class ItemPedido(object): 113 | """um item de um pedido""" 114 | 115 | qtd = Quantidade() 116 | descr = Palavras(2) 117 | pr_unitario = Quantidade() 118 | 119 | def __init__(self, descr, pr_unitario, qtd): 120 | self.descr = descr 121 | self.qtd = qtd 122 | self.pr_unitario = pr_unitario 123 | 124 | @classmethod 125 | def listar_descritores(cls): 126 | lista_descr = [(atr._instance_index, nome, atr) 127 | for nome, atr in cls.__dict__.items() 128 | if isinstance(atr, ValidatedDescriptor)] 129 | for index, nome, atr in sorted(lista_descr): 130 | print '%12s : %s' % (nome, atr.__class__.__name__) 131 | 132 | -------------------------------------------------------------------------------- /atributos/metaclasses/pedido7.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | """ 4 | Exemplo de uma classe com descritores 5 | 6 | A classe ItemPedido deve ser instanciada com os dados essenciais que sao: 7 | descricao do item, preco unitario e quantidade. 8 | 9 | >>> bolas = ItemPedido('bola de golf', 2, 10) 10 | >>> bolas.descr 11 | 'bola de golf' 12 | >>> bolas.qtd 13 | 10 14 | 15 | O atributo qtd de um ItemPedido nunca pode ser <= 0: 16 | 17 | >>> duendes = ItemPedido('duende verde', 2.99, 0) 18 | Traceback (most recent call last): 19 | ... 20 | TypeError: qtd deve ser > 0 21 | >>> duendes = ItemPedido('duende verde', 2.99, 13) 22 | >>> duendes.qtd 23 | 13 24 | >>> duendes.qtd = -1 25 | Traceback (most recent call last): 26 | ... 27 | TypeError: qtd deve ser > 0 28 | >>> duendes.qtd = 20 29 | >>> duendes.qtd 30 | 20 31 | 32 | O preco também nao pode ser <= 0: 33 | 34 | >>> saci = ItemPedido('saci perere', -1, 10) 35 | Traceback (most recent call last): 36 | ... 37 | TypeError: pr_unitario deve ser > 0 38 | 39 | 40 | E a descricao deve ter pelo menos duas palavras: 41 | 42 | >>> saci = ItemPedido('saci', -1, 10) 43 | Traceback (most recent call last): 44 | ... 45 | TypeError: descr deve ter pelo menos 2 palavras 46 | 47 | 48 | Podemos obter a lista dos descritores de ItemPedido, na ordem em que 49 | foram declarados em ItemPedido: 50 | 51 | >>> ItemPedido.listar_descritores() 52 | qtd : Quantidade 53 | descr : Palavras 54 | pr_unitario : Quantidade 55 | 56 | 57 | """ 58 | 59 | from abc import ABCMeta, abstractmethod 60 | from operator import attrgetter 61 | 62 | class OrderedDescriptor(object): 63 | __metaclass__ = ABCMeta 64 | 65 | __instance_counter = 0 66 | 67 | def __new__(cls, *args): 68 | new_instance = object.__new__(cls) 69 | new_instance._instance_index = OrderedDescriptor.__instance_counter 70 | OrderedDescriptor.__instance_counter += 1 71 | return new_instance 72 | 73 | class ValidatedDescriptor(OrderedDescriptor): 74 | __metaclass__ = ABCMeta 75 | 76 | @abstractmethod 77 | def validator(self, instance, value): 78 | """Return value or raise TypeError for invalid values 79 | 80 | This method is invoked by the __set__ method of the descriptor. 81 | Parameters are the same for __set__: self, instance, value. 82 | """ 83 | 84 | def __set__(self, instance, value): 85 | if not hasattr(self, 'attr_name'): 86 | for name, attr in instance.__class__.__dict__.items(): 87 | if attr is self: 88 | self.attr_name = name 89 | break 90 | else: # only if the for loop terminates without break 91 | assert False, 'descriptor not found in class' 92 | # template method pattern: delegar validacao para subclasses 93 | value = self.validator(instance, value) 94 | setattr(instance, '__'+self.attr_name, value) 95 | 96 | def __get__(self, instance, owner): 97 | return getattr(instance, '__'+self.attr_name) 98 | 99 | class Quantidade(ValidatedDescriptor): 100 | def validator(self, instance, value): 101 | value = int(value) 102 | if value < 1: 103 | raise TypeError('%s deve ser > 0' % self.attr_name) 104 | return value 105 | 106 | class Palavras(ValidatedDescriptor): 107 | def __init__(self, min_palavras): 108 | self.min_palavras = min_palavras 109 | 110 | def validator(self, instance, value): 111 | if len(value.split()) < self.min_palavras: 112 | msg = '%s deve ter pelo menos %s palavras' 113 | raise TypeError(msg % (self.attr_name, self.min_palavras)) 114 | return value 115 | 116 | class OrderedModelMeta(type): 117 | def __new__(cls, name, bases, dict_): 118 | dict['_ordered_descriptors'] = sorted([attr 119 | for attr in dict_.values() 120 | if isinstance(attr, OrderedDescriptor)], 121 | key=attrgetter('_instance_index')) 122 | return type.__new__(cls, name, bases, dict_) 123 | 124 | class OrderedModel(object): 125 | __metaclass__ = OrderedModelMeta 126 | 127 | class ItemPedido(OrderedModel): 128 | """um item de um pedido""" 129 | 130 | qtd = Quantidade() 131 | descr = Palavras(2) 132 | pr_unitario = Quantidade() 133 | 134 | def __init__(self, descr, pr_unitario, qtd): 135 | self.descr = descr 136 | self.qtd = qtd 137 | self.pr_unitario = pr_unitario 138 | 139 | @classmethod 140 | def listar_descritores(cls): 141 | for atr in cls._ordered_descriptors: 142 | print '%12s : %s' % (atr.attr_name, atr.__class__.__name__) 143 | 144 | -------------------------------------------------------------------------------- /atributos/metaclasses/pedido8.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | """ 4 | Exemplo de uma classe com descritores 5 | 6 | A classe ItemPedido deve ser instanciada com os dados essenciais que sao: 7 | descricao do item, preco unitario e quantidade. 8 | 9 | >>> bolas = ItemPedido('bola de golf', 2, 10) 10 | >>> bolas.descr 11 | 'bola de golf' 12 | >>> bolas.qtd 13 | 10 14 | 15 | O atributo qtd de um ItemPedido nunca pode ser <= 0: 16 | 17 | >>> duendes = ItemPedido('duende verde', 2.99, 0) 18 | Traceback (most recent call last): 19 | ... 20 | TypeError: qtd deve ser > 0 21 | >>> duendes = ItemPedido('duende verde', 2.99, 13) 22 | >>> duendes.qtd 23 | 13 24 | >>> duendes.qtd = -1 25 | Traceback (most recent call last): 26 | ... 27 | TypeError: qtd deve ser > 0 28 | >>> duendes.qtd = 20 29 | >>> duendes.qtd 30 | 20 31 | 32 | O preco também nao pode ser <= 0: 33 | 34 | >>> saci = ItemPedido('saci perere', -1, 10) 35 | Traceback (most recent call last): 36 | ... 37 | TypeError: pr_unitario deve ser > 0 38 | 39 | 40 | E a descricao deve ter pelo menos duas palavras: 41 | 42 | >>> saci = ItemPedido('saci', -1, 10) 43 | Traceback (most recent call last): 44 | ... 45 | TypeError: descr deve ter pelo menos 2 palavras 46 | 47 | 48 | Podemos obter a lista dos descritores de ItemPedido, na ordem em que 49 | foram declarados em ItemPedido: 50 | 51 | >>> ItemPedido.listar_descritores() 52 | qtd : Quantidade 53 | descr : Palavras 54 | pr_unitario : Quantidade 55 | 56 | 57 | """ 58 | 59 | from abc import ABCMeta, abstractmethod 60 | from operator import attrgetter 61 | 62 | class OrderedDescriptor(object): 63 | __metaclass__ = ABCMeta 64 | 65 | __instance_counter = 0 66 | 67 | def __new__(cls, *args): 68 | new_instance = object.__new__(cls) 69 | new_instance._instance_index = OrderedDescriptor.__instance_counter 70 | OrderedDescriptor.__instance_counter += 1 71 | return new_instance 72 | 73 | class ValidatedDescriptor(OrderedDescriptor): 74 | __metaclass__ = ABCMeta 75 | 76 | @abstractmethod 77 | def validator(self, instance, value): 78 | """Return value or raise TypeError for invalid values 79 | 80 | This method is invoked by the __set__ method of the descriptor. 81 | Parameters are the same for __set__: self, instance, value. 82 | """ 83 | 84 | def __set__(self, instance, value): 85 | # template method pattern: delegar validacao para subclasses 86 | value = self.validator(instance, value) 87 | setattr(instance, '__'+self.attr_name, value) 88 | 89 | def __get__(self, instance, owner): 90 | return getattr(instance, '__'+self.attr_name) 91 | 92 | class Quantidade(ValidatedDescriptor): 93 | def validator(self, instance, value): 94 | value = int(value) 95 | if value < 1: 96 | raise TypeError('%s deve ser > 0' % self.attr_name) 97 | return value 98 | 99 | class Palavras(ValidatedDescriptor): 100 | def __init__(self, min_palavras): 101 | self.min_palavras = min_palavras 102 | 103 | def validator(self, instance, value): 104 | if len(value.split()) < self.min_palavras: 105 | msg = '%s deve ter pelo menos %s palavras' 106 | raise TypeError(msg % (self.attr_name, self.min_palavras)) 107 | return value 108 | 109 | class OrderedModelMeta(type): 110 | def __new__(cls, name, bases, dict): 111 | ordered_descriptors = [] 112 | for name, attr in dict.items(): 113 | if isinstance(attr, OrderedDescriptor): 114 | ordered_descriptors.append(attr) 115 | attr.attr_name = name 116 | ordered_descriptors.sort(key=attrgetter('_instance_index')) 117 | dict['_ordered_descriptors'] = ordered_descriptors 118 | return type.__new__(cls, name, bases, dict) 119 | 120 | class OrderedModel(object): 121 | __metaclass__ = OrderedModelMeta 122 | 123 | @classmethod 124 | def list_ordered_descriptors(cls): 125 | return cls._ordered_descriptors 126 | 127 | class ItemPedido(OrderedModel): 128 | """um item de um pedido""" 129 | 130 | qtd = Quantidade() 131 | descr = Palavras(2) 132 | pr_unitario = Quantidade() 133 | 134 | def __init__(self, descr, pr_unitario, qtd): 135 | self.descr = descr 136 | self.qtd = qtd 137 | self.pr_unitario = pr_unitario 138 | 139 | @classmethod 140 | def listar_descritores(cls): 141 | for atr in cls.list_ordered_descriptors(): 142 | print '%12s : %s' % (atr.attr_name, type(atr).__name__) 143 | 144 | -------------------------------------------------------------------------------- /atributos/metaclasses/pedido9.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | """ 4 | Exemplo de uma classe com descritores 5 | 6 | A classe ItemPedido deve ser instanciada com os dados essenciais que sao: 7 | descricao do item, preco unitario e quantidade. 8 | 9 | >>> bolas = ItemPedido(10, 'bola de golf', 2) 10 | >>> bolas.descr 11 | 'bola de golf' 12 | >>> bolas.qtd 13 | 10 14 | 15 | O atributo qtd de um ItemPedido nunca pode ser <= 0: 16 | 17 | >>> duendes = ItemPedido(0, 'duende verde', 2.99) 18 | Traceback (most recent call last): 19 | ... 20 | TypeError: qtd deve ser > 0 21 | >>> duendes = ItemPedido(13, 'duende verde', 2.99) 22 | >>> duendes.qtd 23 | 13 24 | >>> duendes.qtd = -1 25 | Traceback (most recent call last): 26 | ... 27 | TypeError: qtd deve ser > 0 28 | >>> duendes.qtd = 20 29 | >>> duendes.qtd 30 | 20 31 | 32 | O preco também nao pode ser <= 0: 33 | 34 | >>> saci = ItemPedido(10, 'saci perere', -1) 35 | Traceback (most recent call last): 36 | ... 37 | TypeError: pr_unitario deve ser > 0 38 | 39 | 40 | E a descricao deve ter pelo menos duas palavras: 41 | 42 | >>> saci = ItemPedido(10, 'saci', 10) 43 | Traceback (most recent call last): 44 | ... 45 | TypeError: descr deve ter pelo menos 2 palavras 46 | 47 | 48 | Podemos obter a lista dos descritores de ItemPedido, na ordem em que 49 | foram declarados em ItemPedido: 50 | 51 | >>> ItemPedido.listar_descritores() 52 | qtd : Quantidade 53 | descr : Palavras 54 | pr_unitario : Quantidade 55 | 56 | >>> ItemPedido.__name__ 57 | 'ItemPedido' 58 | 59 | 60 | """ 61 | 62 | from abc import ABCMeta, abstractmethod 63 | from operator import attrgetter 64 | 65 | class OrderedDescriptor(object): 66 | __metaclass__ = ABCMeta 67 | 68 | __instance_counter = 0 69 | 70 | def __new__(cls, *args): 71 | new_instance = object.__new__(cls) 72 | new_instance._instance_index = OrderedDescriptor.__instance_counter 73 | OrderedDescriptor.__instance_counter += 1 74 | return new_instance 75 | 76 | class ValidatedDescriptor(OrderedDescriptor): 77 | __metaclass__ = ABCMeta 78 | 79 | @abstractmethod 80 | def validator(self, instance, value): 81 | """Return value or raise TypeError for invalid values 82 | 83 | This method is invoked by the __set__ method of the descriptor. 84 | Parameters are the same for __set__: self, instance, value. 85 | """ 86 | 87 | def __set__(self, instance, value): 88 | # template method pattern: delegar validacao para subclasses 89 | value = self.validator(instance, value) 90 | setattr(instance, '__'+self.attr_name, value) 91 | 92 | def __get__(self, instance, owner): 93 | return getattr(instance, '__'+self.attr_name) 94 | 95 | class Quantidade(ValidatedDescriptor): 96 | def validator(self, instance, value): 97 | value = int(value) 98 | if value < 1: 99 | raise TypeError('%s deve ser > 0' % self.attr_name) 100 | return value 101 | 102 | class Palavras(ValidatedDescriptor): 103 | def __init__(self, min_palavras): 104 | self.min_palavras = min_palavras 105 | 106 | def validator(self, instance, value): 107 | if len(value.split()) < self.min_palavras: 108 | msg = '%s deve ter pelo menos %s palavras' 109 | raise TypeError(msg % (self.attr_name, self.min_palavras)) 110 | return value 111 | 112 | class OrderedModelMeta(type): 113 | def __new__(cls, name, bases, dict): 114 | ordered_descriptors = [] 115 | for key, attr in dict.items(): 116 | if isinstance(attr, OrderedDescriptor): 117 | ordered_descriptors.append(attr) 118 | attr.attr_name = key 119 | ordered_descriptors.sort(key=attrgetter('_instance_index')) 120 | dict['_ordered_descriptors'] = ordered_descriptors 121 | return type.__new__(cls, name, bases, dict) 122 | 123 | class OrderedModel(object): 124 | __metaclass__ = OrderedModelMeta 125 | 126 | def __init__(self, *args): 127 | for arg, atrib in zip(args, self.list_ordered_descriptors()): 128 | setattr(self, atrib.attr_name, arg) 129 | 130 | @classmethod 131 | def list_ordered_descriptors(cls): 132 | return cls._ordered_descriptors 133 | 134 | class ItemPedido(OrderedModel): 135 | """um item de um pedido""" 136 | 137 | qtd = Quantidade() 138 | descr = Palavras(2) 139 | pr_unitario = Quantidade() 140 | 141 | @classmethod 142 | def listar_descritores(cls): 143 | for atr in cls.list_ordered_descriptors(): 144 | print '%12s : %s' % (atr.attr_name, type(atr).__name__) 145 | 146 | -------------------------------------------------------------------------------- /atributos/ordprops.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | """ 5 | Em Python os atributos de uma classe são armazenados em um `dict`, portanto 6 | sua ordem não é preservada. Normalmente a ordem não é realmente importante. 7 | 8 | Note no exemplo abaixo que a lista devolvida por `dir(l)` não preserva 9 | a ordem em que foram declarados os atributos na classe `Livro`:: 10 | 11 | >>> class LivroSimples(object): 12 | ... titulo = u'' 13 | ... isbn = u'' 14 | ... autores = u'' 15 | >>> l = LivroSimples() 16 | >>> dir(l) #doctest: +ELLIPSIS 17 | [...'autores', 'isbn', 'titulo'...] 18 | 19 | Para gerar formulários automaticamente a partir da classe, é desejável 20 | respeitar a ordem de declaração dos campos. Usando descritores e uma 21 | metaclasse, é possível preservar esta ordem. 22 | 23 | >>> class Livro(OrderedModel): 24 | ... titulo = OrderedProperty() 25 | ... isbn = OrderedProperty() 26 | ... autores = OrderedProperty() 27 | >>> l2 = Livro() 28 | >>> l2.titulo = 'O Alienista' 29 | >>> l2.titulo 30 | 'O Alienista' 31 | >>> list(l2) 32 | ['titulo', 'isbn', 'autores'] 33 | >>> for campo in l2: print campo 34 | titulo 35 | isbn 36 | autores 37 | >>> l3 = Livro() 38 | >>> l3.titulo is None 39 | True 40 | >>> l4 = Livro(titulo=u'Alice', autores=[u'Carroll', u'Tenniel'], isbn=u'9781234567890') 41 | >>> for campo, valor in l4.iteritems(): 42 | ... print '%-8s: %s' % (campo, valor) 43 | titulo : Alice 44 | isbn : 9781234567890 45 | autores : [u'Carroll', u'Tenniel'] 46 | 47 | Os descritores têm um atributo `order` que é inicializado com um contador da 48 | classe `OrderedProperty` incrementado a cada nova instância. A metaclasse usa 49 | este atributo `order` para ordenar uma lista com os nomes dos campos. 50 | 51 | """ 52 | 53 | from operator import attrgetter 54 | 55 | class OrderedProperty(object): 56 | __count = 0 57 | 58 | def __init__(self): 59 | self.order = self.__class__.__count 60 | self.__class__.__count += 1 61 | 62 | def __get__(self, instance, cls): 63 | return getattr(instance, self.name, None) 64 | 65 | def __set__(self, instance, value): 66 | setattr(instance, self.name, value) 67 | 68 | def __repr__(self): 69 | return '<%s %s>' % (self.__class__.__name__, self.name) 70 | 71 | class OrderedMeta(type): 72 | def __new__(cls, name, bases, dict): 73 | props = [] 74 | for key, attr in dict.items(): 75 | if isinstance(attr, OrderedProperty): 76 | attr.name = '_' + key 77 | props.append(attr) 78 | cls._ordered_props = sorted(props, key=attrgetter('order')) 79 | return type.__new__(cls, name, bases, dict) 80 | 81 | class OrderedModel(object): 82 | __metaclass__ = OrderedMeta 83 | 84 | def __init__(self, **kwargs): 85 | for k in kwargs: 86 | setattr(self, k, kwargs[k]) 87 | 88 | def __iter__(self): 89 | return (prop.name[1:] for prop in self.__class__._ordered_props) 90 | 91 | def iteritems(self): 92 | return ((prop.name[1:], getattr(self, prop.name)) 93 | for prop in self.__class__._ordered_props) 94 | 95 | 96 | if __name__=='__main__': 97 | import doctest 98 | doctest.testmod() 99 | 100 | 101 | -------------------------------------------------------------------------------- /atributos/prop_leitura.py: -------------------------------------------------------------------------------- 1 | ''' 2 | 3 | >>> o = C(7) 4 | >>> o.x 5 | 7 6 | >>> o.x = 8 7 | Traceback (most recent call last): 8 | ... 9 | AttributeError: can't set attribute 10 | >>> o._C__x 11 | 7 12 | >>> o._C__x = 9 13 | >>> o.x 14 | 9 15 | 16 | ''' 17 | 18 | class C(object): 19 | def __init__(self, x): 20 | self.__x = x 21 | @property 22 | def x(self): 23 | return self.__x -------------------------------------------------------------------------------- /atributos/t0/descritores.py: -------------------------------------------------------------------------------- 1 | class Quantidade(object): 2 | def __init__(self, nome_atr): 3 | self.nome_atr = nome_atr 4 | self.nome_atr_interno = '__'+nome_atr 5 | 6 | def __get__(self, instance, owner): 7 | return getattr(instance, self.nome_atr_interno) 8 | 9 | def __set__(self, instance, value): 10 | if value > 0: 11 | setattr(instance, self.nome_atr_interno, value) 12 | else: 13 | raise TypeError('%s deve ser > 0' % self.nome_atr) 14 | -------------------------------------------------------------------------------- /atributos/t0/pedido.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | """ 5 | Exemplo de uma classe com um propriedade:: 6 | 7 | >>> bolas = ItemPedido('bolas de golfe', 5.00, 6) 8 | >>> bolas.preco_unit 9 | 5.0 10 | >>> bolas.qtd 11 | 6 12 | >>> bolas.total() 13 | 30.0 14 | 15 | Este exemplo ilustra a implementacao de uma propriedade usando 16 | o decorator @property para evitar quantidades negativas:: 17 | 18 | >>> duendes = ItemPedido('duende verde', 300, -1) 19 | Traceback (most recent call last): 20 | ... 21 | TypeError: quantidade deve ser > 0 22 | >>> duendes = ItemPedido('duende verde', 0, 10) 23 | Traceback (most recent call last): 24 | ... 25 | TypeError: preco_unit deve ser > 0 26 | 27 | Queremos que seja proibido atribuir uma quantidade negativa a uma 28 | instancia de ItemPedido existente:: 29 | 30 | >>> lupas = ItemPedido('lente de aumento 3x', 3.99, 10) 31 | >>> lupas.qtd 32 | 10 33 | >>> lupas.qtd = 12 34 | >>> lupas.qtd 35 | 12 36 | >>> lupas.qtd = -10 37 | Traceback (most recent call last): 38 | ... 39 | TypeError: quantidade deve ser > 0 40 | 41 | 42 | """ 43 | 44 | class ItemPedido(object): 45 | """Representa um item de um pedido. 46 | 47 | Instancias desta classe formam as linhas de uma fatura. 48 | """ 49 | def __init__(self, descr, preco_unit, qtd): 50 | self.descr = descr 51 | if preco_unit > 0: 52 | self.preco_unit = preco_unit 53 | else: 54 | raise TypeError('preco_unit deve ser > 0') 55 | self.qtd = qtd 56 | 57 | def total(self): 58 | return self.preco_unit * self.qtd 59 | 60 | @property 61 | def qtd(self): 62 | return self.__qtd 63 | 64 | @qtd.setter 65 | def qtd(self, valor): 66 | if valor > 0: 67 | self.__qtd = valor 68 | else: 69 | raise TypeError('quantidade deve ser > 0') 70 | -------------------------------------------------------------------------------- /atributos/t0/pedido2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | """ 5 | Exemplo de uma classe com um propriedade:: 6 | 7 | >>> bolas = ItemPedido('bolas de golfe', 5.00, 6) 8 | >>> bolas.preco_unit 9 | 5.0 10 | >>> bolas.qtd 11 | 6 12 | >>> bolas.total() 13 | 30.0 14 | 15 | Este exemplo ilustra a implementacao de uma propriedade usando 16 | o decorator @property para evitar quantidades negativas:: 17 | 18 | >>> duendes = ItemPedido('duende verde', 300, -1) 19 | Traceback (most recent call last): 20 | ... 21 | TypeError: qtd deve ser > 0 22 | >>> duendes = ItemPedido('duende verde', 0, 10) 23 | Traceback (most recent call last): 24 | ... 25 | TypeError: preco_unit deve ser > 0 26 | 27 | Queremos que seja proibido atribuir uma quantidade negativa a uma 28 | instancia de ItemPedido existente:: 29 | 30 | >>> lupas = ItemPedido('lente de aumento 3x', 3.99, 10) 31 | >>> lupas.qtd 32 | 10 33 | >>> lupas.qtd = 12 34 | >>> lupas.qtd 35 | 12 36 | >>> lupas.qtd = -10 37 | Traceback (most recent call last): 38 | ... 39 | TypeError: qtd deve ser > 0 40 | 41 | 42 | """ 43 | 44 | from descritores import Quantidade 45 | 46 | class ItemPedido(object): 47 | """Representa um item de um pedido. 48 | 49 | Instancias desta classe formam as linhas de uma fatura. 50 | """ 51 | 52 | qtd = Quantidade('qtd') 53 | preco_unit = Quantidade('preco_unit') 54 | 55 | def __init__(self, descr, preco_unit, qtd): 56 | self.descr = descr 57 | self.preco_unit = preco_unit 58 | self.qtd = qtd 59 | 60 | def total(self): 61 | return self.preco_unit * self.qtd 62 | -------------------------------------------------------------------------------- /atributos/t0/pedido4.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | """ 5 | Exemplo de uma classe com um propriedade:: 6 | 7 | >>> bolas = ItemPedido('bolas de golfe', 5.00, 6) 8 | >>> bolas.preco_unit 9 | 5.0 10 | >>> bolas.qtd 11 | 6 12 | >>> bolas.total() 13 | 30.0 14 | 15 | Este exemplo ilustra a implementacao de uma propriedade usando 16 | o decorator @property para evitar quantidades negativas:: 17 | 18 | >>> duendes = ItemPedido('duende verde', 300, -1) 19 | Traceback (most recent call last): 20 | ... 21 | TypeError: qtd deve ser > 0 22 | >>> duendes = ItemPedido('duende verde', 0, 10) 23 | Traceback (most recent call last): 24 | ... 25 | TypeError: preco_unit deve ser > 0 26 | 27 | Queremos que seja proibido atribuir uma quantidade negativa a uma 28 | instancia de ItemPedido existente:: 29 | 30 | >>> lupas = ItemPedido('lente de aumento 3x', 3.99, 10) 31 | >>> lupas.qtd 32 | 10 33 | >>> lupas.qtd = 12 34 | >>> lupas.qtd 35 | 12 36 | >>> lupas.qtd = -10 37 | Traceback (most recent call last): 38 | ... 39 | TypeError: qtd deve ser > 0 40 | 41 | 42 | """ 43 | 44 | class Quantidade(object): 45 | def __get__(self, instance, owner): 46 | return getattr(instance, '__'+self.nome_atr) 47 | 48 | def __set__(self, instance, value): 49 | if value > 0: 50 | setattr(instance, '__'+self.nome_atr, value) 51 | else: 52 | raise TypeError('%s deve ser > 0' % self.nome_atr) 53 | 54 | class ItemPedido(object): 55 | """Representa um item de um pedido. 56 | 57 | Instancias desta classe formam as linhas de uma fatura. 58 | """ 59 | 60 | qtd = Quantidade() 61 | preco_unit = Quantidade() 62 | 63 | def nomear_descritores(self, cls): 64 | for nome, valor in cls.__dict__.items(): 65 | if isinstance(valor, Quantidade): 66 | valor.nome_atr = nome 67 | 68 | def __init__(self, descr, preco_unit, qtd): 69 | self.nomear_descritores(self.__class__) 70 | self.descr = descr 71 | self.preco_unit = preco_unit 72 | self.qtd = qtd 73 | 74 | def total(self): 75 | return self.preco_unit * self.qtd 76 | 77 | if __name__=='__main__': 78 | import doctest 79 | doctest.testmod(optionflags=doctest.REPORT_ONLY_FIRST_FAILURE) 80 | -------------------------------------------------------------------------------- /baralho_listcomp.py: -------------------------------------------------------------------------------- 1 | >>> naipes = ['espadas','copas','ouros','paus'] 2 | >>> cartas = [str(x) for x in range(2,11)] + ['J','Q','K','A'] 3 | >>> baralho = [(carta,naipe) for carta in cartas for naipe in naipes] 4 | >>> baralho 5 | [('2', 'espadas'), ('2', 'copas'), ('2', 'ouros'), ('2', 'paus'), 6 | ('3', 'espadas'), ('3', 'copas'), ('3', 'ouros'), ('3', 'paus'), 7 | ('4', 'espadas'), ('4', 'copas'), ('4', 'ouros'), ('4', 'paus'), 8 | ('5', 'espadas'), ('5', 'copas'), ('5', 'ouros'), ('5', 'paus'), 9 | ('6', 'espadas'), ('6', 'copas'), ('6', 'ouros'), ('6', 'paus'), 10 | ('7', 'espadas'), ('7', 'copas'), ('7', 'ouros'), ('7', 'paus'), 11 | ('8', 'espadas'), ('8', 'copas'), ('8', 'ouros'), ('8', 'paus'), 12 | ('9', 'espadas'), ('9', 'copas'), ('9', 'ouros'), ('9', 'paus'), 13 | ('10', 'espadas'), ('10', 'copas'), ('10', 'ouros'), ('10', 'paus'), 14 | ('J', 'espadas'), ('J', 'copas'), ('J', 'ouros'), ('J', 'paus'), 15 | ('Q', 'espadas'), ('Q', 'copas'), ('Q', 'ouros'), ('Q', 'paus'), 16 | ('K', 'espadas'), ('K', 'copas'), ('K', 'ouros'), ('K', 'paus'), 17 | ('A', 'espadas'), ('A', 'copas'), ('A', 'ouros'), ('A', 'paus')] 18 | >>> 19 | -------------------------------------------------------------------------------- /funcional/funcao_1a_classe.py: -------------------------------------------------------------------------------- 1 | ''' 2 | 3 | >>> def dobro(n=1): 4 | ... """Devolve duas vezes n""" 5 | ... return n*2 6 | >>> dobro(21) 7 | 42 8 | >>> dobro('X') 9 | 'XX' 10 | >>> dobro([10, 20, 30]) 11 | [10, 20, 30, 10, 20, 30] 12 | >>> dobro #doctest: +ELLIPSIS 13 | 14 | >>> type(dobro) 15 | 16 | >>> x2 = dobro 17 | >>> x2(1234) 18 | 2468 19 | >>> map(dobro, [11, 22, 33]) 20 | [22, 44, 66] 21 | >>> dobro.__doc__ 22 | 'Devolve duas vezes n' 23 | >>> dobro.__name__ 24 | 'dobro' 25 | >>> def fat(n=5): 26 | ... if n < 2: return 1 27 | ... return n*fat(n-1) 28 | >>> fat(10) 29 | 3628800 30 | >>> atr_func = ['__closure__','__code__', '__defaults__', '__dict__', '__name__'] 31 | >>> for atr in atr_func: #doctest:+ELLIPSIS 32 | ... print '%14s : %r' % (atr, getattr(fat, atr)) 33 | __closure__ : None 34 | __code__ : 35 | __defaults__ : (5,) 36 | __dict__ : {} 37 | __name__ : 'fat' 38 | >>> atr_co = [a for a in dir(fat.__code__) if a.startswith('co_')] 39 | >>> for atr in atr_co: #doctest:+ELLIPSIS 40 | ... print '%14s : %r' % (atr, getattr(fat.__code__, atr)) 41 | co_argcount : 1 42 | co_cellvars : () 43 | co_code : '|\\x00\\x00d\\x01\\x00k\\x00...S' 44 | co_consts : (None, 2, 1) 45 | co_filename : '' 46 | co_firstlineno : 1 47 | co_flags : 67 48 | co_freevars : () 49 | co_lnotab : '\\x00\\x01\\x0c\\x00\\x04\\x01' 50 | co_name : 'fat' 51 | co_names : ('fat',) 52 | co_nlocals : 1 53 | co_stacksize : 4 54 | co_varnames : ('n',) 55 | >>> from dis import dis 56 | >>> dis(fat.__code__.co_code) #doctest: +NORMALIZE_WHITESPACE 57 | 0 LOAD_FAST 0 (0) 58 | 3 LOAD_CONST 1 (1) 59 | 6 COMPARE_OP 0 (<) 60 | 9 POP_JUMP_IF_FALSE 16 61 | 12 LOAD_CONST 2 (2) 62 | 15 RETURN_VALUE 63 | >> 16 LOAD_FAST 0 (0) 64 | 19 LOAD_GLOBAL 0 (0) 65 | 22 LOAD_FAST 0 (0) 66 | 25 LOAD_CONST 2 (2) 67 | 28 BINARY_SUBTRACT 68 | 29 CALL_FUNCTION 1 69 | 32 BINARY_MULTIPLY 70 | 33 RETURN_VALUE 71 | 72 | 73 | 74 | 75 | >>> tf = type(dobro) 76 | >>> fonte = """def triplo(n): return n*3""" 77 | >>> bytecode = compile(fonte,'__teste__', 'exec') 78 | >>> triplo = tf(bytecode, globals()) 79 | ''' -------------------------------------------------------------------------------- /funcional/lambda.py: -------------------------------------------------------------------------------- 1 | ''' 2 | 3 | >>> dobro = lambda n: n * 2 4 | >>> dobro(7) 5 | 14 6 | 7 | >>> lista = [1, 2, 3, 4, 5] 8 | >>> reduce(lambda a, b: a+b, lista) 9 | 15 10 | >>> from operator import add, mul 11 | >>> reduce(add, lista) 12 | 15 13 | >>> sum(lista) 14 | 15 15 | >>> reduce(mul, lista) 16 | 120 17 | >>> fat = lambda x: 1 if x < 2 else reduce(mul, range(x,1,-1)) 18 | >>> fat(5) 19 | 120 20 | 21 | 22 | ''' -------------------------------------------------------------------------------- /funcional/roman_closure.py: -------------------------------------------------------------------------------- 1 | 2 | def to_roman(): 3 | 4 | romanNumeralMap = ( 5 | ('M', 1000), ('CM', 900), ('D', 500), ('CD', 400), ('C', 100), ('XC', 90), 6 | ('L', 50), ('XL', 40), ('X', 10), ('IX', 9), ('V', 5), ('IV', 4), ('I', 1)) 7 | 8 | def _to_roman(n): 9 | result = '' 10 | for numeral, integer in romanNumeralMap: 11 | while n >= integer: 12 | result += numeral 13 | n -= integer 14 | return result 15 | return _to_roman 16 | 17 | to_roman = to_roman() 18 | for i in range(1, 21): 19 | print to_roman(i) -------------------------------------------------------------------------------- /funcional/sort.py: -------------------------------------------------------------------------------- 1 | ''' 2 | 3 | >>> class Auto(): 4 | ... def __init__(self, modelo, ano): 5 | ... self.modelo = modelo 6 | ... self.ano = ano 7 | ... def __repr__(self): 8 | ... return '' % self.__dict__ 9 | >>> a6 = Auto('Audi A6', 2007) 10 | >>> merc = Auto('Mercedes S6', 2001) 11 | >>> fusca = Auto('Fusca 1600', 1966) 12 | >>> carros = [fusca, merc, a6] 13 | >>> carros.sort() 14 | >>> carros 15 | [, , ] 16 | >>> carros.sort(lambda a,b: cmp(a.ano, b.ano)) 17 | >>> carros 18 | [, , ] 19 | >>> sorted(carros, key=lambda carro: carro.modelo) 20 | [, , ] 21 | >>> from operator import attrgetter 22 | >>> sorted(carros, key=attrgetter('modelo')) 23 | [, , ] 24 | >>> sorted(carros, key=attrgetter('ano')) 25 | [, , ] 26 | >>> f = attrgetter('ano') 27 | >>> f(fusca) 28 | 1966 29 | >>> f(merc) 30 | 2001 31 | 32 | ''' -------------------------------------------------------------------------------- /iteraveis/baralho.py: -------------------------------------------------------------------------------- 1 | ''' 2 | >>> from baralho import Baralho 3 | >>> b = Baralho() 4 | >>> b[0] 5 | 6 | >>> b[:3] 7 | [, <2 de copas>, <3 de copas>] 8 | >>> b[-3:] 9 | [, , ] 10 | >>> for carta in b: # doctest:+ELLIPSIS 11 | ... print carta 12 | 13 | <2 de copas> 14 | <3 de copas> 15 | <4 de copas> 16 | <5 de copas> 17 | ... 18 | >>> for carta in reversed(b): # doctest:+ELLIPSIS 19 | ... print carta 20 | 21 | 22 | 23 | <10 de paus> 24 | ... 25 | >>> 26 | 27 | ''' 28 | 29 | 30 | from random import shuffle 31 | 32 | class Carta(object): 33 | def __init__(self, valor, naipe): 34 | self.valor = valor 35 | self.naipe = naipe 36 | 37 | def __repr__(self): 38 | return '<%s de %s>' % (self.valor, self.naipe) 39 | 40 | class Baralho(object): 41 | naipes = 'copas ouros espadas paus'.split() 42 | valores = 'A 2 3 4 5 6 7 8 9 10 J Q K'.split() 43 | 44 | def __init__(self): 45 | self.cartas = [Carta(v, n) 46 | for n in self.naipes 47 | for v in self.valores] 48 | 49 | def __getitem__(self, pos): 50 | return self.cartas[pos] 51 | 52 | def __len__(self): 53 | return len(self.cartas) 54 | -------------------------------------------------------------------------------- /iteraveis/baralho_iter_genexp.py: -------------------------------------------------------------------------------- 1 | ''' 2 | >>> b = Baralho() 3 | >>> for carta in b: # doctest:+ELLIPSIS 4 | ... print carta 5 | 6 | <2 de copas> 7 | <3 de copas> 8 | <4 de copas> 9 | <5 de copas> 10 | ... 11 | 12 | ''' 13 | 14 | from random import shuffle 15 | 16 | class Carta(object): 17 | def __init__(self, valor, naipe): 18 | self.valor = valor 19 | self.naipe = naipe 20 | 21 | def __repr__(self): 22 | return '<%s de %s>' % (self.valor, self.naipe) 23 | 24 | class Baralho(object): 25 | naipes = 'copas ouros espadas paus'.split() 26 | valores = 'A 2 3 4 5 6 7 8 9 10 J Q K'.split() 27 | 28 | def __init__(self): 29 | self.cartas = [Carta(v, n) 30 | for n in self.naipes 31 | for v in self.valores] 32 | 33 | def __len__(self): 34 | return len(self.cartas) 35 | 36 | def __iter__(self): 37 | return (carta for carta in self.cartas) 38 | -------------------------------------------------------------------------------- /iteraveis/baralho_iter_gerador.py: -------------------------------------------------------------------------------- 1 | ''' 2 | >>> b = Baralho() 3 | >>> for carta in b: # doctest:+ELLIPSIS 4 | ... print carta 5 | 6 | <2 de copas> 7 | <3 de copas> 8 | <4 de copas> 9 | <5 de copas> 10 | ... 11 | 12 | ''' 13 | 14 | from random import shuffle 15 | 16 | class Carta(object): 17 | def __init__(self, valor, naipe): 18 | self.valor = valor 19 | self.naipe = naipe 20 | 21 | def __repr__(self): 22 | return '<%s de %s>' % (self.valor, self.naipe) 23 | 24 | class Baralho(object): 25 | naipes = 'copas ouros espadas paus'.split() 26 | valores = 'A 2 3 4 5 6 7 8 9 10 J Q K'.split() 27 | 28 | def __init__(self): 29 | self.cartas = [Carta(v, n) 30 | for n in self.naipes 31 | for v in self.valores] 32 | 33 | def __len__(self): 34 | return len(self.cartas) 35 | 36 | def __iter__(self): 37 | for carta in self.cartas: 38 | yield carta 39 | -------------------------------------------------------------------------------- /iteraveis/baralho_iter_oo.py: -------------------------------------------------------------------------------- 1 | ''' 2 | >>> b = Baralho() 3 | >>> for carta in b: # doctest:+ELLIPSIS 4 | ... print carta 5 | 6 | <2 de copas> 7 | <3 de copas> 8 | <4 de copas> 9 | <5 de copas> 10 | ... 11 | 12 | ''' 13 | 14 | from random import shuffle 15 | 16 | class Carta(object): 17 | def __init__(self, valor, naipe): 18 | self.valor = valor 19 | self.naipe = naipe 20 | 21 | def __repr__(self): 22 | return '<%s de %s>' % (self.valor, self.naipe) 23 | 24 | class Baralho(object): 25 | naipes = 'copas ouros espadas paus'.split() 26 | valores = 'A 2 3 4 5 6 7 8 9 10 J Q K'.split() 27 | 28 | def __init__(self): 29 | self.cartas = [Carta(v, n) 30 | for n in self.naipes 31 | for v in self.valores] 32 | 33 | def __len__(self): 34 | return len(self.cartas) 35 | 36 | def __iter__(self): 37 | return IteradorBaralho(self) 38 | 39 | class IteradorBaralho(object): 40 | def __init__(self, baralho): 41 | self.index = 0 42 | self.baralho = baralho 43 | def next(self): 44 | if self.index == len(self.baralho): 45 | raise StopIteration() 46 | # o iterador conhece a implementacao do Baralho 47 | res = self.baralho.cartas[self.index] 48 | self.index += 1 49 | return res 50 | def __iter__(self): 51 | return self -------------------------------------------------------------------------------- /iteraveis/baralho_misturado.py: -------------------------------------------------------------------------------- 1 | ''' 2 | >>> def inverte(l): 3 | ... l.reverse() 4 | >>> b = Baralho(inverte) 5 | >>> for carta in b: # doctest:+ELLIPSIS 6 | ... print carta 7 | 8 | 9 | 10 | <10 de paus> 11 | <9 de paus> 12 | ... 13 | 14 | ''' 15 | 16 | from random import shuffle 17 | 18 | class Carta(object): 19 | def __init__(self, valor, naipe): 20 | self.valor = valor 21 | self.naipe = naipe 22 | 23 | def __repr__(self): 24 | return '<%s de %s>' % (self.valor, self.naipe) 25 | 26 | class Baralho(object): 27 | naipes = 'copas ouros espadas paus'.split() 28 | valores = 'A 2 3 4 5 6 7 8 9 10 J Q K'.split() 29 | 30 | def __init__(self, embaralhador=shuffle): 31 | self.embaralhador = embaralhador 32 | self.cartas = [Carta(v, n) 33 | for n in self.naipes 34 | for v in self.valores] 35 | 36 | def __len__(self): 37 | return len(self.cartas) 38 | 39 | def __iter__(self): 40 | indice = range(len(self.cartas)) 41 | self.embaralhador(indice) 42 | for i in indice: 43 | yield self.cartas[i] 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /iteraveis/busca_bin.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | # Código testado com Python 2.7, 3.2, PyPy(1.7) 2.7 e Jython 2.5.2 4 | 5 | """ 6 | >>> l = [] 7 | >>> busca_bin(l, 0) 8 | -1 9 | >>> l = [7] 10 | >>> [busca_bin(l, x) for x in [0, 7, 8]] 11 | [-1, 0, -1] 12 | >>> l = [2, 4] 13 | >>> [busca_bin(l, x) for x in l] 14 | [0, 1] 15 | >>> [busca_bin(l, x) for x in [1, 3, 5]] 16 | [-1, -1, -1] 17 | >>> l = [1, 3, 5] 18 | >>> [busca_bin(l, x) for x in l] 19 | [0, 1, 2] 20 | >>> [busca_bin(l, x) for x in [0, 2, 4, 6]] 21 | [-1, -1, -1, -1] 22 | >>> l = [1, 2, 3, 4] 23 | >>> [busca_bin(l, x) for x in l] 24 | [0, 1, 2, 3] 25 | >>> [busca_bin(l, x) for x in [0, 1.5, 4.1]] 26 | [-1, -1, -1] 27 | 28 | """ 29 | 30 | try: 31 | xrange 32 | except NameError: 33 | xrange = range # para funcionar no Python 3 34 | 35 | def busca_bin(seq, item): 36 | """Assumindo que `seq` está ordenada, devolve a posição do `item`. 37 | 38 | Se `item` não está presente em `seq`, devolve -1. 39 | """ 40 | a, b = 0, len(seq) 41 | i = -1 42 | while (a < b): 43 | i_ant = i 44 | i = (a+b)//2 45 | if i == i_ant: 46 | break 47 | atual = seq[i] 48 | if item == atual: 49 | return i 50 | elif item < atual: 51 | b = i 52 | else: 53 | a = i 54 | return -1 55 | 56 | def busca_lin_enum(seq, item): 57 | for i, valor in enumerate(seq): 58 | if valor == item: 59 | return i 60 | return -1 61 | 62 | def busca_lin_for(seq, item): 63 | for i in xrange(len(seq)): 64 | if seq[i] == item: 65 | return i 66 | return -1 67 | 68 | def busca_lin_while(seq, item): 69 | i = 0 70 | while i < len(seq): 71 | if seq[i] == item: 72 | return i 73 | i += 1 74 | return -1 75 | 76 | def busca_index(seq, item): 77 | try: 78 | return seq.index(item) 79 | except ValueError: 80 | return -1 81 | 82 | def desempenho(): 83 | import sys 84 | from timeit import Timer 85 | print(sys.version) 86 | tam = 10**6 87 | expr = '''b(l, %d), b(l, %d), b(l, %d)''' % (0, tam/2, tam) 88 | for nome_busca in (k for k in sorted(globals()) if k.startswith('busca')): 89 | prep = '\n'.join([ 90 | '''from __main__ import %s as b\n''' % nome_busca, 91 | '''l = list(range(%d))''' % tam]) # Python 2 e 3: list(range(n)) 92 | res = min(Timer(expr, prep).repeat(number=10)) 93 | print('%15s: %12.8f' % (nome_busca, res)) 94 | 95 | def teste(): 96 | import doctest 97 | return doctest.testmod()[0] # devolver falhas 98 | 99 | if __name__=='__main__': 100 | falhas = teste() 101 | if not falhas: 102 | desempenho() 103 | -------------------------------------------------------------------------------- /iteraveis/demo_genexp.py: -------------------------------------------------------------------------------- 1 | from time import sleep, strftime 2 | import sys 3 | 4 | verboso = len(sys.argv) == 2 and sys.argv[1] == '-v' 5 | 6 | def demora(ts=1): 7 | agora = strftime('%H:%M:%S') 8 | print 'demorando...', agora 9 | sleep(1) 10 | return agora 11 | 12 | if verboso: 13 | print 'Teste com list comprehension [listcomp]' 14 | print ' repare como todas as demoras acontecem primeiro,' 15 | print ' depois o resultado aparece todo de repente.' 16 | raw_input('(tecle para rodar o teste LISTCOMP) ') 17 | 18 | for t in [demora() for i in range(3)]: 19 | print t 20 | 21 | if verboso: 22 | print 23 | print 'Teste com expressao geradora (genexp)' 24 | print ' repare que acontece uma demora e aparece um resultado,' 25 | print ' depois outra demora e outro resultado, ate o fim' 26 | raw_input('(tecle para rodar o teste GENEXP) ') 27 | 28 | for t in (demora() for i in range(3)): 29 | print t 30 | -------------------------------------------------------------------------------- /iteraveis/demo_iter2.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | def dado(): 4 | return randint(1,6) 5 | 6 | # gera valores ate que um 6 seja sorteado 7 | for r in iter(dado, 6): # 6 e' o "sentinela" 8 | print r 9 | -------------------------------------------------------------------------------- /iteraveis/demo_iter2_partial.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | from functools import partial 3 | 4 | # exibe valores ate que um 6 seja sorteado 5 | # 6 e' o "sentinela" 6 | for r in iter(partial(randint,1,6), 6): 7 | print r 8 | -------------------------------------------------------------------------------- /iteraveis/genexp_x_listcomp.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | ''' 5 | >>> for i in [letra for letra in gera_letra()]: 6 | ... print i 7 | ... 8 | gerando 'A'... 9 | gerando 'B'... 10 | gerando 'C'... 11 | A 12 | B 13 | C 14 | >>> for i in (letra for letra in gera_letra()): 15 | ... print i 16 | ... 17 | gerando 'A'... 18 | A 19 | gerando 'B'... 20 | B 21 | gerando 'C'... 22 | C 23 | ''' 24 | 25 | def gera_letra(ultima='C', verboso=True): 26 | cod = ord('A') 27 | while chr(cod) <= ultima: 28 | letra = chr(cod) 29 | if verboso: 30 | print 'gerando %r...' % letra 31 | yield letra 32 | cod += 1 33 | 34 | if __name__=='__main__': 35 | import doctest 36 | doctest.testmod() 37 | -------------------------------------------------------------------------------- /iteraveis/lista_ord.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | ''' 4 | Testes de `__contains__` mixin de `Sequence` 5 | (faz busca linear via `__getitem__`):: 6 | 7 | >>> lo = ListaOrdenada([3,2,1]) 8 | >>> 1 in lo, 2 in lo, 3 in lo 9 | (True, True, True) 10 | >>> 0 in lo, 4 in lo 11 | (False, False) 12 | >>> lo = ListaOrdenada([3,2,4,1]) 13 | >>> 1 in lo, 2 in lo, 3 in lo, 4 in lo 14 | (True, True, True, True) 15 | >>> 0 in lo, 5 in lo 16 | (False, False) 17 | >>> lo = ListaOrdenada([7]) 18 | >>> 6 in lo, 7 in lo, 8 in lo 19 | (False, True, False) 20 | >>> lo = ListaOrdenada([]) 21 | >>> 0 in lo 22 | False 23 | 24 | Testes de `add`:: 25 | 26 | >>> lo = ListaOrdenada([]) 27 | >>> lo.add(3); list(lo) 28 | [3] 29 | >>> lo.add(5); list(lo) # doctest: +SKIP 30 | [3, 5] 31 | >>> lo.add(4); list(lo) # doctest: +SKIP 32 | [3, 4, 5] 33 | >>> lo.add(2); list(lo) # doctest: +SKIP 34 | [2, 3, 4, 5] 35 | >>> lo.add(3); list(lo) # doctest: +SKIP 36 | [2, 3, 3, 4, 5] 37 | 38 | ''' 39 | 40 | from collections import Sequence 41 | 42 | class ListaOrdenada(Sequence): 43 | def __init__(self, iteravel): 44 | self.__lista = list(sorted(iteravel)) 45 | 46 | def __getitem__(self, index): 47 | return self.__lista[index] 48 | 49 | def __len__(self): 50 | return len(self.__lista) 51 | 52 | def add(self, novo): 53 | """Insere um item na lista ordenada, mantendo a ordem.""" 54 | raise NotImplementedError('Exercício: implementar este médodo') 55 | 56 | def desempenho(): 57 | from timeit import repeat 58 | from pprint import pprint 59 | tam = 10**5 60 | expr = '''0 in l, %d in l, %d in l''' % (tam/2, tam) 61 | prep = '\n'.join([ 62 | '''from __main__ import ListaOrdenada''', 63 | '''l = ListaOrdenada(range(%d))''' % tam]) 64 | res = repeat(expr, prep, number=10) 65 | print(min(res)) 66 | 67 | def teste(): 68 | import doctest 69 | return doctest.testmod()[0] # devolver falhas 70 | 71 | if __name__=='__main__': 72 | falhas = teste() 73 | if not falhas: 74 | desempenho() 75 | -------------------------------------------------------------------------------- /iteraveis/repl_batch.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | 5 | def interactive_reader(): 6 | while True: 7 | try: 8 | line = raw_input('> ') 9 | except KeyboardInterrupt: 10 | print 11 | break 12 | if line.strip() == 'quit': 13 | break 14 | yield line 15 | 16 | def file_reader(file_name): 17 | with open(file_name) as f: 18 | for line in f: 19 | yield line.rstrip() 20 | 21 | def repl(line_reader, echo): 22 | for line in line_reader: 23 | if echo: 24 | print ':', line 25 | line = line.strip() 26 | if line.startswith('print '): 27 | print line[6:] 28 | 29 | if __name__=='__main__': 30 | if len(sys.argv) == 1: 31 | line_reader = interactive_reader() 32 | echo = True 33 | else: 34 | line_reader = file_reader(sys.argv[1]) 35 | echo = False 36 | repl(line_reader, echo) 37 | 38 | -------------------------------------------------------------------------------- /iteraveis/texto.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | """ 5 | Acesso por palavras:: 6 | 7 | >>> txt = Texto(u'Poema que aconteceu') 8 | >>> for palavra in txt.palavras(): print palavra 9 | Poema 10 | que 11 | aconteceu 12 | 13 | """ 14 | 15 | class Texto(object): 16 | def __init__(self, ustr): 17 | self.ustr = ustr 18 | 19 | def palavras(self): 20 | for parte in self.ustr.split(): 21 | yield parte 22 | raise StopIteration 23 | 24 | 25 | def testar(): 26 | import doctest 27 | doctest.testmod() 28 | 29 | if __name__=='__main__': 30 | testar() -------------------------------------------------------------------------------- /metaprog/execucao.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import atexit 3 | 4 | print '-> 1 inicio' 5 | 6 | def funcaoA(): 7 | print '-> 2 funcao A' 8 | return 'resultado A' 9 | 10 | def funcaoB(): 11 | print '-> 3 funcao B' 12 | 13 | def funcaoC(): 14 | print '-> 4 funcao C' 15 | 16 | return funcaoC 17 | 18 | funcaoD = lambda:sys.stdout.write('-> 5 funcao D\n') 19 | 20 | def funcaoE(): 21 | print '-> 6 funcao E' 22 | 23 | def funcaoF(): 24 | print '-> 7 funcao F' 25 | 26 | class Classe(object): 27 | print '-> 8 bloco de declaracoes da Classe' 28 | 29 | def __init__(self): 30 | print '-> 9 inicializacao da instancia da Classe' 31 | 32 | def metodo(self, default=funcaoF()): 33 | print '-> 10 metodo da instancia da Classe' 34 | return 'resultado metodo' 35 | 36 | class ClasseInterna(object): 37 | print '-> 11 bloco de declaracoes da ClasseInterna' 38 | 39 | def __del__(self): 40 | print '-> 12 destruicao da instancia da Classe' 41 | 42 | if True: 43 | print '-> 13 condicional True' 44 | 45 | if False: 46 | assert False, 'Isso nunca devia acontecer' 47 | 48 | atexit.register(funcaoE) 49 | 50 | print '-> 14 logo antes do if __main__' 51 | 52 | if __name__=='__main__': 53 | print '-> 15 __main__' 54 | print funcaoA 55 | print funcaoA() 56 | print '-> 16 __main__ (cont.)' 57 | print funcaoB 58 | resultadoB = funcaoB() 59 | print resultadoB 60 | objeto = Classe() 61 | objeto.metodo() 62 | resultadoB() 63 | print funcaoD 64 | funcaoD() 65 | class Local(object): 66 | print '-> 17 bloco de declaracoes da classe Local' 67 | print '-> 18 __main__ (final)' 68 | print '-> 19 FIM' 69 | -------------------------------------------------------------------------------- /metaprog/execucao_import.py: -------------------------------------------------------------------------------- 1 | print '=> ponto I' 2 | 3 | import execucao 4 | 5 | print '=> ponto II' 6 | -------------------------------------------------------------------------------- /metaprog/execucao_vars.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | a = 10 4 | b = 20 5 | c = 30 6 | d = 40 7 | 8 | def func_a(): 9 | print a # this is a reference to the global variable 10 | return 'result of func_a' 11 | 12 | def func_b(): 13 | print b # referencing 'b' here causes UnboundLocalError 14 | assert False, 'this line is never executed' 15 | b = 22 16 | return 'result of func_b' 17 | 18 | def func_c(): 19 | print c # referencing 'c' here causes UnboundLocalError 20 | if False: 21 | c = 33 # this line is unreachable, but the compiler sees c on the 22 | # left side of an assignment, and treats it as a local variable 23 | return 'result of func_c' 24 | 25 | def func_d(): 26 | print d # this is a reference to the global variable 27 | def inner(): 28 | d = 33 # this creates a variable local to inner 29 | inner() 30 | return 'result of func_d' 31 | 32 | def test_a(): 33 | res_a = '' 34 | res_a = func_a() 35 | assert res_a == 'result of func_a' 36 | 37 | def test_b(): 38 | res_b = '' 39 | try: 40 | res_b = func_b() 41 | except UnboundLocalError as e: 42 | assert e.args[0] == "local variable 'b' referenced before assignment" 43 | else: 44 | assert False, 'an UnboundLocalError excepion was expected but not raised' 45 | assert res_b == '' 46 | 47 | def test_c(): 48 | res_c = '' 49 | try: 50 | res_c = func_c() 51 | except UnboundLocalError as e: 52 | assert e.args[0] == "local variable 'c' referenced before assignment" 53 | else: 54 | assert False, 'an UnboundLocalError excepion was expected but not raised' 55 | assert res_c == '' 56 | 57 | def test_d(): 58 | res_d = '' 59 | res_d = func_d() 60 | assert res_d == 'result of func_d' 61 | 62 | if __name__=='__main__': 63 | test_a() 64 | test_b() 65 | test_c() 66 | test_d() 67 | ''' 68 | import dis 69 | dis.dis(func_a.__code__.co_code) 70 | print '*' * 70 71 | dis.dis(func_b.__code__.co_code) 72 | ''' 73 | -------------------------------------------------------------------------------- /metaprog/lista_tipada.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | ''' 4 | 5 | Um exemplo inspirado pela pergunta "Python tem polimorfismo parametrizado?". 6 | A pergunta veio de um estudante de Java, e e' como perguntar "O carro eletrico 7 | tem escapamento?". O carro eletrico nao tem escapamento porque nao precisa, 8 | e Python nao tem polimorfismo parametrizado (tambem conhecido como "generics" 9 | no mundo Java) porque nao precisa disso. Todas as colecoes embutidas em Python 10 | sao genericas por natureza. 11 | 12 | Porem, e o objetivo e' *limitar* o tipo de dado que se pode colocar em uma lista, 13 | eis um exemplo de como fazer isso: 14 | 15 | >>> l = ListaLimitada(str) 16 | >>> l.append('bla') 17 | >>> len(l) 18 | 1 19 | >>> l[0] 20 | 'bla' 21 | >>> l[0] = 'bli' 22 | >>> l[0] 23 | 'bli' 24 | >>> l[0] = 2 25 | Traceback (most recent call last): 26 | ... 27 | TypeError: Esta lista aceita apenas tipo 28 | >>> l.append('blu') 29 | >>> len(l) 30 | 2 31 | >>> l.append(3.1592) 32 | Traceback (most recent call last): 33 | ... 34 | TypeError: Esta lista aceita apenas tipo 35 | 36 | 37 | ''' 38 | 39 | class ListaLimitada(list): 40 | def __init__(self, tipo, *args, **kwargs): 41 | super(ListaLimitada,self).__init__(*args, **kwargs) 42 | self.tipo = tipo 43 | 44 | def __checa_tipo(self, item): 45 | # import pdb; pdb.set_trace() 46 | if isinstance(item, self.tipo): 47 | nome_tipo = self.tipo.__name__ 48 | raise TypeError('Esta lista aceita apenas tipo <%s>'% nome_tipo) 49 | 50 | def __setitem__(self, pos, item): 51 | self.__checa_tipo(item) 52 | super(ListaLimitada,self).__setitem__(pos, item) 53 | 54 | def append(self, item): 55 | self.__checa_tipo(item) 56 | super(ListaLimitada,self).append(item) 57 | 58 | 59 | 60 | if __name__=='__main__': 61 | import doctest 62 | print doctest.testmod() 63 | -------------------------------------------------------------------------------- /metaprog/ordinais.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | ''' 5 | Os itens contidos em objetos da classe Lista podem ser acessados pelos 6 | ordinais de 'primeiro' até 'decimo', ou por abreviaturas de três letras 7 | destes ordinais: 8 | 9 | >>> l = Lista([11, 22, 33, 44, 55]) 10 | >>> l.primeiro 11 | 11 12 | >>> l.ter 13 | 33 14 | 15 | Se não existe a posição correspondente:: 16 | 17 | >>> l.oitavo 18 | Traceback (most recent call last): 19 | ... 20 | AttributeError: Este objeto 'Lista' nao tem 'oitavo' item. 21 | 22 | O último também pode ser acessado como um atributo, mas a implementação 23 | neste caso é bem diferente: 24 | 25 | >>> l.ult 26 | 55 27 | 28 | Quando não sabemos o que fazer com o atributo acessado, é melhor levantar 29 | a tradicional exceção AttributeError: 30 | 31 | >>> l.spam 32 | Traceback (most recent call last): 33 | ... 34 | AttributeError: 'Lista' object has no attribute 'spam' 35 | 36 | Isso vale também para atributos que começam com três letras de uma sigla 37 | mas não coincidem a partir da quarta letra:: 38 | 39 | >>> l.primata 40 | Traceback (most recent call last): 41 | ... 42 | AttributeError: 'Lista' object has no attribute 'primata' 43 | 44 | 45 | ''' 46 | 47 | from itertools import count 48 | 49 | class Lista(list): 50 | 51 | __ordinais = ('primeiro segundo terceiro quarto quinto sexto setimo' 52 | ' oitavo nono decimo').split() 53 | __abrevs = [s[:3] for s in __ordinais] 54 | 55 | def __getattr__(self, atrib): 56 | for i, ordinal, abrev in zip(count(), self.__ordinais, self.__abrevs): 57 | if atrib == ordinal or (len(atrib)>=3 and ordinal.startswith(atrib)): 58 | if i < len(self): 59 | return self[i] 60 | else: 61 | msg = "Este objeto '%s' nao tem '%s' item." 62 | raise AttributeError(msg % (self.__class__.__name__, atrib)) 63 | 64 | msg = "'%s' object has no attribute '%s'" 65 | raise AttributeError(msg % (self.__class__.__name__, atrib)) 66 | 67 | @property 68 | def ultimo(self): 69 | return self[-1] 70 | 71 | ult = ultimo 72 | 73 | 74 | if __name__=='__main__': 75 | import doctest 76 | doctest.testmod() 77 | 78 | -------------------------------------------------------------------------------- /metaprog/ordinais2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # Implementação usando properties pré-definidas 5 | 6 | ''' 7 | Os itens contidos em objetos da classe TuplaOrdinal podem ser acessados pelos 8 | ordinais de 'primeiro' até 'decimo':: 9 | 10 | >>> t = TuplaOrdinal((11, 22, 33, 44, 55)) 11 | >>> t.primeiro 12 | 11 13 | >>> t.terceiro 14 | 33 15 | 16 | O último também pode ser acessado como um atributo, mas a implementação 17 | neste caso é bem diferente: 18 | 19 | >>> t.ultimo 20 | 55 21 | 22 | Se não existe o item correspondente:: 23 | 24 | >>> t.decimo 25 | Traceback (most recent call last): 26 | ... 27 | IndexError: tuple index out of range 28 | 29 | Porém:: 30 | 31 | >>> t.vigesimo 32 | Traceback (most recent call last): 33 | ... 34 | AttributeError: 'TuplaOrdinal' object has no attribute 'vigesimo' 35 | 36 | ''' 37 | 38 | from operator import itemgetter 39 | 40 | class TuplaOrdinal(tuple): 41 | 42 | __ordinais = ('primeiro segundo terceiro quarto quinto sexto setimo' 43 | ' oitavo nono decimo').split() 44 | 45 | def __init__(self, *args, **kwargs): 46 | super(TuplaOrdinal,self).__init__(*args, **kwargs) 47 | for i, ordinal in enumerate(self.__ordinais): 48 | setattr(self.__class__, ordinal, property(itemgetter(i))) 49 | 50 | @property 51 | def ultimo(self): 52 | return self[-1] 53 | 54 | ult = ultimo 55 | 56 | 57 | if __name__=='__main__': 58 | import doctest 59 | doctest.testmod() 60 | 61 | 62 | 63 | --------------------------------------------------------------------------------