├── .gitignore ├── NZBmegasearch ├── ApiModule.py ├── DeepsearchModule.py ├── SearchModule.py ├── SearchModules │ ├── Newznab.py │ ├── __init__.py │ ├── ad_NZBclub.py │ ├── ah_WMBidx.py │ ├── al_OMGwtf.py │ └── am_PirateNzb.py ├── SuggestionModule.py ├── WarperModule.py ├── beautifulsoup.py ├── builtin_params.ini ├── certificates │ ├── server.crt │ └── server.key ├── changelog.txt ├── config_settings.py ├── detachedtrend.py ├── flask │ ├── __init__.py │ ├── app.py │ ├── blueprints.py │ ├── config.py │ ├── ctx.py │ ├── debughelpers.py │ ├── exceptions.py │ ├── ext │ │ └── __init__.py │ ├── exthook.py │ ├── globals.py │ ├── helpers.py │ ├── logging.py │ ├── module.py │ ├── session.py │ ├── sessions.py │ ├── signals.py │ ├── templating.py │ ├── testing.py │ ├── views.py │ └── wrappers.py ├── jinja2 │ ├── __init__.py │ ├── _debugsupport.c │ ├── _markupsafe │ │ ├── __init__.py │ │ ├── _bundle.py │ │ ├── _constants.py │ │ ├── _native.py │ │ └── tests.py │ ├── _stringdefs.py │ ├── bccache.py │ ├── compiler.py │ ├── constants.py │ ├── debug.py │ ├── defaults.py │ ├── environment.py │ ├── exceptions.py │ ├── ext.py │ ├── filters.py │ ├── lexer.py │ ├── loaders.py │ ├── meta.py │ ├── nodes.py │ ├── optimizer.py │ ├── parser.py │ ├── runtime.py │ ├── sandbox.py │ ├── tests.py │ ├── testsuite │ │ ├── __init__.py │ │ ├── api.py │ │ ├── core_tags.py │ │ ├── debug.py │ │ ├── doctests.py │ │ ├── ext.py │ │ ├── filters.py │ │ ├── imports.py │ │ ├── inheritance.py │ │ ├── lexnparse.py │ │ ├── loader.py │ │ ├── regression.py │ │ ├── res │ │ │ ├── __init__.py │ │ │ └── templates │ │ │ │ ├── broken.html │ │ │ │ ├── foo │ │ │ │ └── test.html │ │ │ │ ├── syntaxerror.html │ │ │ │ └── test.html │ │ ├── security.py │ │ ├── tests.py │ │ └── utils.py │ ├── utils.py │ └── visitor.py ├── large_server │ ├── nginx.conf │ ├── nginx_install.md │ └── supervisor │ │ ├── conf.d │ │ ├── README │ │ ├── detachedtrend.conf │ │ ├── mega.conf │ │ └── nginx.conf │ │ └── supervisord.conf ├── license.txt ├── logs │ └── placeholder ├── mechanize │ ├── __init__.py │ ├── _auth.py │ ├── _beautifulsoup.py │ ├── _clientcookie.py │ ├── _debug.py │ ├── _firefox3cookiejar.py │ ├── _form.py │ ├── _gzip.py │ ├── _headersutil.py │ ├── _html.py │ ├── _http.py │ ├── _lwpcookiejar.py │ ├── _markupbase.py │ ├── _mechanize.py │ ├── _mozillacookiejar.py │ ├── _msiecookiejar.py │ ├── _opener.py │ ├── _pullparser.py │ ├── _request.py │ ├── _response.py │ ├── _rfc3986.py │ ├── _sgmllib_copy.py │ ├── _sockettimeout.py │ ├── _testcase.py │ ├── _urllib2.py │ ├── _urllib2_fork.py │ ├── _useragent.py │ ├── _util.py │ └── _version.py ├── mega2.py ├── megasearch.py ├── miscdefs.py ├── nzbsanity.py ├── openshift │ ├── app.py │ ├── application │ ├── install_openshift.sh │ └── openshift_install.md ├── requests │ ├── __init__.py │ ├── adapters.py │ ├── api.py │ ├── auth.py │ ├── cacert.pem │ ├── certs.py │ ├── compat.py │ ├── cookies.py │ ├── exceptions.py │ ├── hooks.py │ ├── models.py │ ├── packages │ │ ├── __init__.py │ │ ├── charade │ │ │ ├── __init__.py │ │ │ ├── big5freq.py │ │ │ ├── big5prober.py │ │ │ ├── chardistribution.py │ │ │ ├── charsetgroupprober.py │ │ │ ├── charsetprober.py │ │ │ ├── codingstatemachine.py │ │ │ ├── compat.py │ │ │ ├── constants.py │ │ │ ├── escprober.py │ │ │ ├── escsm.py │ │ │ ├── eucjpprober.py │ │ │ ├── euckrfreq.py │ │ │ ├── euckrprober.py │ │ │ ├── euctwfreq.py │ │ │ ├── euctwprober.py │ │ │ ├── gb2312freq.py │ │ │ ├── gb2312prober.py │ │ │ ├── hebrewprober.py │ │ │ ├── jisfreq.py │ │ │ ├── jpcntx.py │ │ │ ├── langbulgarianmodel.py │ │ │ ├── langcyrillicmodel.py │ │ │ ├── langgreekmodel.py │ │ │ ├── langhebrewmodel.py │ │ │ ├── langhungarianmodel.py │ │ │ ├── langthaimodel.py │ │ │ ├── latin1prober.py │ │ │ ├── mbcharsetprober.py │ │ │ ├── mbcsgroupprober.py │ │ │ ├── mbcssm.py │ │ │ ├── sbcharsetprober.py │ │ │ ├── sbcsgroupprober.py │ │ │ ├── sjisprober.py │ │ │ ├── universaldetector.py │ │ │ └── utf8prober.py │ │ └── urllib3 │ │ │ ├── __init__.py │ │ │ ├── _collections.py │ │ │ ├── connectionpool.py │ │ │ ├── contrib │ │ │ ├── __init__.py │ │ │ └── ntlmpool.py │ │ │ ├── exceptions.py │ │ │ ├── filepost.py │ │ │ ├── packages │ │ │ ├── __init__.py │ │ │ ├── ordered_dict.py │ │ │ ├── six.py │ │ │ └── ssl_match_hostname │ │ │ │ └── __init__.py │ │ │ ├── poolmanager.py │ │ │ ├── request.py │ │ │ ├── response.py │ │ │ └── util.py │ ├── sessions.py │ ├── status_codes.py │ ├── structures.py │ └── utils.py ├── static │ ├── arrow-down.png │ ├── block-ui.js │ ├── cfg_cp_offline.jpg │ ├── cfg_offline.jpg │ ├── cp_logo.png │ ├── error.png │ ├── error_hover.png │ ├── favicon.ico │ ├── imdb.png │ ├── jquery.min.js │ ├── loadingicon.gif │ ├── log.png │ ├── nzb2_16.png │ ├── nzb2_16_no.png │ ├── nzb2_16_ok.png │ ├── off.png │ ├── ok.png │ ├── ok_hover.png │ ├── options.png │ ├── predb_1st.png │ ├── predb_2nd.png │ ├── reset.css │ ├── reset2.css │ ├── restart.png │ ├── sab2_16.png │ ├── sab2_16_no.png │ ├── sab2_16_ok.png │ ├── sb_cp.png │ ├── show_config.jpg │ ├── show_search.jpg │ ├── sick_logo.png │ ├── style.css │ ├── thetvdb16.png │ ├── title.png │ ├── toggle-switch.css │ ├── vex-theme-default.css │ ├── vex.combined.min.js │ └── vex.css ├── templates │ ├── api.html │ ├── api_default.html │ ├── api_error.html │ ├── config.html │ ├── connectinfo.html │ ├── legal.html │ ├── loginfo.html │ ├── main_page.html │ ├── restart.html │ └── rss.html ├── vernum.num └── werkzeug │ ├── __init__.py │ ├── _internal.py │ ├── contrib │ ├── __init__.py │ ├── atom.py │ ├── cache.py │ ├── fixers.py │ ├── iterio.py │ ├── jsrouting.py │ ├── kickstart.py │ ├── limiter.py │ ├── lint.py │ ├── profiler.py │ ├── securecookie.py │ ├── sessions.py │ ├── testtools.py │ └── wrappers.py │ ├── datastructures.py │ ├── debug │ ├── __init__.py │ ├── console.py │ ├── repr.py │ ├── shared │ │ ├── FONT_LICENSE │ │ ├── console.png │ │ ├── debugger.js │ │ ├── jquery.js │ │ ├── less.png │ │ ├── more.png │ │ ├── source.png │ │ ├── style.css │ │ └── ubuntu.ttf │ └── tbtools.py │ ├── exceptions.py │ ├── formparser.py │ ├── http.py │ ├── local.py │ ├── posixemulation.py │ ├── routing.py │ ├── script.py │ ├── security.py │ ├── serving.py │ ├── templates.py │ ├── test.py │ ├── testapp.py │ ├── testsuite │ ├── __init__.py │ ├── compat.py │ ├── contrib │ │ ├── __init__.py │ │ ├── cache.py │ │ ├── fixers.py │ │ ├── iterio.py │ │ ├── securecookie.py │ │ ├── sessions.py │ │ └── wrappers.py │ ├── datastructures.py │ ├── debug.py │ ├── exceptions.py │ ├── formparser.py │ ├── http.py │ ├── internal.py │ ├── local.py │ ├── multipart │ │ ├── collect.py │ │ ├── firefox3-2png1txt │ │ │ ├── file1.png │ │ │ ├── file2.png │ │ │ ├── request.txt │ │ │ └── text.txt │ │ ├── firefox3-2pnglongtext │ │ │ ├── file1.png │ │ │ ├── file2.png │ │ │ ├── request.txt │ │ │ └── text.txt │ │ ├── ie6-2png1txt │ │ │ ├── file1.png │ │ │ ├── file2.png │ │ │ ├── request.txt │ │ │ └── text.txt │ │ ├── ie7_full_path_request.txt │ │ ├── opera8-2png1txt │ │ │ ├── file1.png │ │ │ ├── file2.png │ │ │ ├── request.txt │ │ │ └── text.txt │ │ └── webkit3-2png1txt │ │ │ ├── file1.png │ │ │ ├── file2.png │ │ │ ├── request.txt │ │ │ └── text.txt │ ├── res │ │ └── test.txt │ ├── routing.py │ ├── security.py │ ├── serving.py │ ├── test.py │ ├── urls.py │ ├── utils.py │ ├── wrappers.py │ └── wsgi.py │ ├── urls.py │ ├── useragents.py │ ├── utils.py │ ├── wrappers.py │ └── wsgi.py └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # General 2 | *.bak 3 | *.ini 4 | *.log 5 | *.tmp 6 | 7 | # Compiled python 8 | *.py[co] 9 | 10 | # OS generated files 11 | *~ 12 | .DS_Store 13 | .Trashes 14 | desktop.ini 15 | ehthumbs.db 16 | Thumbs.db 17 | 18 | custom_params.ini 19 | -------------------------------------------------------------------------------- /NZBmegasearch/SearchModules/__init__.py: -------------------------------------------------------------------------------- 1 | # # ## # ## # ## # ## # ## # ## # ## # ## # ## # ## # ## # ## # ## # ## # 2 | # ~ This file is part of NZBmegasearch by pillone. 3 | # ~ 4 | # ~ NZBmegasearch is free software: you can redistribute it and/or modify 5 | # ~ it under the terms of the GNU General Public License as published by 6 | # ~ the Free Software Foundation, either version 3 of the License, or 7 | # ~ (at your option) any later version. 8 | # ~ 9 | # ~ NZBmegasearch is distributed in the hope that it will be useful, 10 | # ~ but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # ~ GNU General Public License for more details. 13 | # ~ 14 | # ~ You should have received a copy of the GNU General Public License 15 | # ~ along with NZBmegasearch. If not, see . 16 | # # ## # ## # ## # ## # ## # ## # ## # ## # ## # ## # ## # ## # ## # ## # 17 | -------------------------------------------------------------------------------- /NZBmegasearch/builtin_params.ini: -------------------------------------------------------------------------------- 1 | [general] 2 | port = 5000 3 | general_user = 4 | general_pwd = 5 | config_user = 6 | config_pwd = 7 | general_https = 0 8 | trends = 0 9 | search_default = 10 | search_suggestions = 0 11 | default_timeout = 20 12 | max_log_size = 20000000 13 | max_log_backupcount = 1 14 | seed_warptable = 11045 15 | trends_refreshrate = 3600 16 | timeout_fast = 3 17 | timeout_slow = 30 18 | stats_key = nzbm1 19 | motd = 20 | trends_qty = 5 21 | smartsearch = 1 22 | use_warp = 0 23 | cache_active = 1 24 | max_cache_age = 12 25 | max_cache_qty = 20 26 | general_dereferer = 1 27 | daysretention = 2960 28 | searchaddontxt = 29 | revproxy = -------------------------------------------------------------------------------- /NZBmegasearch/certificates/server.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICJTCCAY4CCQDV2zjOv5IOyDANBgkqhkiG9w0BAQUFADBXMRUwEwYDVQQHDAxQ 3 | bGFuZXQgRWFydGgxFjAUBgNVBAoMDU5aQm1lZ2FzZWFyY2gxFjAUBgNVBAsMDU5a 4 | Qm1lZ2FzZWFyY2gxDjAMBgNVBAMMBTBieXRlMB4XDTEzMDQyNzE3MTg1M1oXDTE0 5 | MDQyNzE3MTg1M1owVzEVMBMGA1UEBwwMUGxhbmV0IEVhcnRoMRYwFAYDVQQKDA1O 6 | WkJtZWdhc2VhcmNoMRYwFAYDVQQLDA1OWkJtZWdhc2VhcmNoMQ4wDAYDVQQDDAUw 7 | Ynl0ZTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAs4+vqCeSa30PQmL9S7KU 8 | f1PdkDJ0JmNGkHac+gAsoOseL3s5ep58cMchsCjtnTCXsfcqayG2irwp8AOgjUce 9 | UCuDHL8yOaAVSmrsygVzdHDHFcu/jlAkAaGNHQ7QfoXeHNJl7Em6ltccO/t3C2+c 10 | gGeNqPXCbnGy4JEi89EThPkCAwEAATANBgkqhkiG9w0BAQUFAAOBgQBCNS6pO6Wx 11 | S3zh3Izw2nkire/osfEx5jg2MffdQJMPOQYXMqBFu28dt9jYnEinsoLnAauVkclY 12 | TZoEcsy+I5N0I0TPNnRP2UsnkyaphtCgE50xEYrV8WrtMLiiSA+xla3IfnjvWo6k 13 | g48vDFzxtkMfkkcJ0qQVJUrwGNF4dzZPRw== 14 | -----END CERTIFICATE----- 15 | -------------------------------------------------------------------------------- /NZBmegasearch/certificates/server.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICWwIBAAKBgQCzj6+oJ5JrfQ9CYv1LspR/U92QMnQmY0aQdpz6ACyg6x4vezl6 3 | nnxwxyGwKO2dMJex9yprIbaKvCnwA6CNRx5QK4McvzI5oBVKauzKBXN0cMcVy7+O 4 | UCQBoY0dDtB+hd4c0mXsSbqW1xw7+3cLb5yAZ42o9cJucbLgkSLz0ROE+QIDAQAB 5 | AoGABl4OCJR+qLkilWQVP13xziIXNUnUvJfApNbP8j2XV41+4IgqHaMJHqaxFyIc 6 | avqSJolxQ6NKadkKU6yNQPVIqdfi/v9XY6TP63dcVpf3JRemdA8ZtJ/lKo+8Buss 7 | wtN5j7zptx50UwQTPp936pPl4RsC3KP/fkyizyYhNWEU3gECQQDl39cf2zTpYY89 8 | iB8MsRdUDUrJ0eaR9hc4lMCZGScxafKrV9uf7Ve/mFBnlzEq6XSxJQLuRWsHJpWg 9 | t2mVv5PJAkEAx/f+bNisIH+1FoCm+QIjFUkGwrmxQpvMyg/cxJ9Tx2mtL0RB/nZI 10 | TQWbFgSjpuhADFVMtYSxAY71y88skXEfsQJAPuIk70oAB3fwv1xlYgtv3kZklyEc 11 | egFgCNJofXksB5B8GfNG2VEMGBWKqUvq31pN2cfOLXA//wzHEdgawiROQQJAKLvl 12 | wfppJb2d/9V5LeQ3jVBw5h25dB4Um1yb1hm2kTp/os8+uj0SAU6RBu0vAQLyeRCv 13 | LZK4E98xRrEPHRl0IQJAeZgDxuDGSooX10CKd7HjJYSnQE6Uhaw2X307Qm3Mkdq3 14 | ikmv0UlC/ZpZVJZERUjYeK8y7qbyo91mrv2uTzCN0g== 15 | -----END RSA PRIVATE KEY----- 16 | -------------------------------------------------------------------------------- /NZBmegasearch/changelog.txt: -------------------------------------------------------------------------------- 1 | Updates 2 | ================ 3 | 4 | Changes in v0.56 5 | + Merged Undeadhunters NzbGet fix 6 | + Merged HackedServers rearranged search priority + tvbid (replaced) 7 | + Replaced tvbid by tvmaze as workaround 8 | + removal of AnimeNzb 9 | 10 | Changes in v0.55 11 | + Changed default timeouts (higher) 12 | + gingadaddy is no longer set to use https 13 | + updated jQuery to 2.1.4 14 | + added option to disable url warping 15 | + changed user agents 16 | + fixed piratenzb not returning any results 17 | + merged fix from cauchy49:cauchy49-patch-api-url-with-proxy-1 18 | 19 | Changes in v0.54 20 | + Fix issue in tvdbid being an int and it expecting a string 21 | 22 | 23 | Changes in v0.53 24 | + no longer asks for the wrong login/pw on accessing the config 25 | + Little code cleanup & reformatting 26 | + Added Anime to Newznab class 27 | + Movie without _HD/_SD will now search both 28 | + Added additional codes for XXX categories 29 | + Fix NzbDrone api Integration 30 | + Fix Sickbeard api integration 31 | + removed nzb.cc 32 | + changed Fanzub to AnimeDB 33 | + upped version numbering 34 | + changed default cache -------------------------------------------------------------------------------- /NZBmegasearch/detachedtrend.py: -------------------------------------------------------------------------------- 1 | # # ## # ## # ## # ## # ## # ## # ## # ## # ## # ## # ## # ## # ## # ## # 2 | # ~ This file is part of NZBmegasearch by 0byte. 3 | # ~ 4 | # ~ NZBmegasearch is free software: you can redistribute it and/or modify 5 | # ~ it under the terms of the GNU General Public License as published by 6 | # ~ the Free Software Foundation, either version 3 of the License, or 7 | # ~ (at your option) any later version. 8 | # ~ 9 | # ~ NZBmegasearch is distributed in the hope that it will be useful, 10 | # ~ but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # ~ GNU General Public License for more details. 13 | # ~ 14 | # ~ You should have received a copy of the GNU General Public License 15 | # ~ along with NZBmegasearch. If not, see . 16 | # # ## # ## # ## # ## # ## # ## # ## # ## # ## # ## # ## # ## # ## # ## # 17 | 18 | from flask import Flask 19 | from flask import request, Response, redirect 20 | import os 21 | import datetime 22 | import threading 23 | from SuggestionModule import SuggestionResponses 24 | import config_settings 25 | import SearchModule 26 | import logging 27 | import logging.handlers 28 | import time 29 | 30 | DEBUGFLAG = True 31 | 32 | motd = '\n\n~*~ ~*~ NZBMegasearcH detached trend ~*~ ~*~' 33 | print motd 34 | 35 | # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 36 | cfgsets = config_settings.CfgSettings() 37 | logsdir = SearchModule.resource_path('logs/') 38 | logging.basicConfig(filename=logsdir + 'nzbmegasearch_detachedtrend.log', level=logging.INFO, 39 | format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') 40 | log = logging.getLogger(__name__) 41 | handler = logging.handlers.RotatingFileHandler(logsdir + 'nzbmegasearch_detachedtrend.log', 42 | maxBytes=cfgsets.cgen['log_size'], 43 | backupCount=cfgsets.cgen['log_backupcount']) 44 | log.addHandler(handler) 45 | log.info(motd) 46 | cfgsets.cgen['trends'] = 1 47 | cfgsets.cgen['search_suggestions'] = 1 48 | cfgsets.cgen['large_server'] = False 49 | sugg = SuggestionResponses(cfgsets.cfg, cfgsets.cgen) 50 | 51 | # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 52 | 53 | def pollsuggestions(): 54 | sugg.asktrend_allparallel() 55 | sugg.asktrend_saveondisk() 56 | 57 | # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 58 | print '>> Waiting default: ' + str(cfgsets.cgen['trends_refreshrate']) 59 | 60 | while 1: 61 | pollsuggestions() 62 | if (len(sugg.movie_trend) == 0 or len(sugg.show_trend) == 0): 63 | print datetime.datetime.now().strftime("%Y-%m-%d %H:%M") + ' Error retreiving trends. Waiting 5s and retrying' 64 | log.info(' Error retreiving trends. Waiting 5s and retrying') 65 | time.sleep(5) 66 | else: 67 | time.sleep(cfgsets.cgen['trends_refreshrate']) 68 | -------------------------------------------------------------------------------- /NZBmegasearch/flask/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | flask 4 | ~~~~~ 5 | 6 | A microframework based on Werkzeug. It's extensively documented 7 | and follows best practice patterns. 8 | 9 | :copyright: (c) 2011 by Armin Ronacher. 10 | :license: BSD, see LICENSE for more details. 11 | """ 12 | 13 | __version__ = '0.9' 14 | 15 | # utilities we import from Werkzeug and Jinja2 that are unused 16 | # in the module but are exported as public interface. 17 | from werkzeug.exceptions import abort 18 | from werkzeug.utils import redirect 19 | from jinja2 import Markup 20 | from jinja2.utils import escape 21 | 22 | from .app import Flask, Request, Response 23 | from .config import Config 24 | from .helpers import url_for, jsonify, json_available, flash, \ 25 | send_file, send_from_directory, get_flashed_messages, \ 26 | get_template_attribute, make_response, safe_join, \ 27 | stream_with_context 28 | from .globals import current_app, g, request, session, _request_ctx_stack, \ 29 | _app_ctx_stack 30 | from .ctx import has_request_context, has_app_context, \ 31 | after_this_request 32 | from .module import Module 33 | from .blueprints import Blueprint 34 | from .templating import render_template, render_template_string 35 | 36 | # the signals 37 | from .signals import signals_available, template_rendered, request_started, \ 38 | request_finished, got_request_exception, request_tearing_down 39 | 40 | # only import json if it's available 41 | if json_available: 42 | from .helpers import json 43 | 44 | # backwards compat, goes away in 1.0 45 | from .sessions import SecureCookieSession as Session 46 | -------------------------------------------------------------------------------- /NZBmegasearch/flask/debughelpers.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | flask.debughelpers 4 | ~~~~~~~~~~~~~~~~~~ 5 | 6 | Various helpers to make the development experience better. 7 | 8 | :copyright: (c) 2011 by Armin Ronacher. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | 12 | 13 | class DebugFilesKeyError(KeyError, AssertionError): 14 | """Raised from request.files during debugging. The idea is that it can 15 | provide a better error message than just a generic KeyError/BadRequest. 16 | """ 17 | 18 | def __init__(self, request, key): 19 | form_matches = request.form.getlist(key) 20 | buf = ['You tried to access the file "%s" in the request.files ' 21 | 'dictionary but it does not exist. The mimetype for the request ' 22 | 'is "%s" instead of "multipart/form-data" which means that no ' 23 | 'file contents were transmitted. To fix this error you should ' 24 | 'provide enctype="multipart/form-data" in your form.' % 25 | (key, request.mimetype)] 26 | if form_matches: 27 | buf.append('\n\nThe browser instead transmitted some file names. ' 28 | 'This was submitted: %s' % ', '.join('"%s"' % x 29 | for x in form_matches)) 30 | self.msg = ''.join(buf).encode('utf-8') 31 | 32 | def __str__(self): 33 | return self.msg 34 | 35 | 36 | class FormDataRoutingRedirect(AssertionError): 37 | """This exception is raised by Flask in debug mode if it detects a 38 | redirect caused by the routing system when the request method is not 39 | GET, HEAD or OPTIONS. Reasoning: form data will be dropped. 40 | """ 41 | 42 | def __init__(self, request): 43 | exc = request.routing_exception 44 | buf = ['A request was sent to this URL (%s) but a redirect was ' 45 | 'issued automatically by the routing system to "%s".' 46 | % (request.url, exc.new_url)] 47 | 48 | # In case just a slash was appended we can be extra helpful 49 | if request.base_url + '/' == exc.new_url.split('?')[0]: 50 | buf.append(' The URL was defined with a trailing slash so ' 51 | 'Flask will automatically redirect to the URL ' 52 | 'with the trailing slash if it was accessed ' 53 | 'without one.') 54 | 55 | buf.append(' Make sure to directly send your %s-request to this URL ' 56 | 'since we can\'t make browsers or HTTP clients redirect ' 57 | 'with form data reliably or without user interaction.' % 58 | request.method) 59 | buf.append('\n\nNote: this exception is only raised in debug mode') 60 | AssertionError.__init__(self, ''.join(buf).encode('utf-8')) 61 | 62 | 63 | def attach_enctype_error_multidict(request): 64 | """Since Flask 0.8 we're monkeypatching the files object in case a 65 | request is detected that does not use multipart form data but the files 66 | object is accessed. 67 | """ 68 | oldcls = request.files.__class__ 69 | 70 | class newcls(oldcls): 71 | def __getitem__(self, key): 72 | try: 73 | return oldcls.__getitem__(self, key) 74 | except KeyError, e: 75 | if key not in request.form: 76 | raise 77 | raise DebugFilesKeyError(request, key) 78 | 79 | newcls.__name__ = oldcls.__name__ 80 | newcls.__module__ = oldcls.__module__ 81 | request.files.__class__ = newcls 82 | -------------------------------------------------------------------------------- /NZBmegasearch/flask/exceptions.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | flask.exceptions 4 | ~~~~~~~~~~~~ 5 | 6 | Flask specific additions to :class:`~werkzeug.exceptions.HTTPException` 7 | 8 | :copyright: (c) 2011 by Armin Ronacher. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | from werkzeug.exceptions import HTTPException, BadRequest 12 | from .helpers import json 13 | 14 | 15 | class JSONHTTPException(HTTPException): 16 | """A base class for HTTP exceptions with ``Content-Type: 17 | application/json``. 18 | 19 | The ``description`` attribute of this class must set to a string (*not* an 20 | HTML string) which describes the error. 21 | 22 | """ 23 | 24 | def get_body(self, environ): 25 | """Overrides :meth:`werkzeug.exceptions.HTTPException.get_body` to 26 | return the description of this error in JSON format instead of HTML. 27 | 28 | """ 29 | return json.dumps(dict(description=self.get_description(environ))) 30 | 31 | def get_headers(self, environ): 32 | """Returns a list of headers including ``Content-Type: 33 | application/json``. 34 | 35 | """ 36 | return [('Content-Type', 'application/json')] 37 | 38 | 39 | class JSONBadRequest(JSONHTTPException, BadRequest): 40 | """Represents an HTTP ``400 Bad Request`` error whose body contains an 41 | error message in JSON format instead of HTML format (as in the superclass). 42 | 43 | """ 44 | 45 | #: The description of the error which occurred as a string. 46 | description = ( 47 | 'The browser (or proxy) sent a request that this server could not ' 48 | 'understand.' 49 | ) 50 | -------------------------------------------------------------------------------- /NZBmegasearch/flask/ext/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | flask.ext 4 | ~~~~~~~~~ 5 | 6 | Redirect imports for extensions. This module basically makes it possible 7 | for us to transition from flaskext.foo to flask_foo without having to 8 | force all extensions to upgrade at the same time. 9 | 10 | When a user does ``from flask.ext.foo import bar`` it will attempt to 11 | import ``from flask_foo import bar`` first and when that fails it will 12 | try to import ``from flaskext.foo import bar``. 13 | 14 | We're switching from namespace packages because it was just too painful for 15 | everybody involved. 16 | 17 | :copyright: (c) 2011 by Armin Ronacher. 18 | :license: BSD, see LICENSE for more details. 19 | """ 20 | 21 | 22 | def setup(): 23 | from ..exthook import ExtensionImporter 24 | 25 | importer = ExtensionImporter(['flask_%s', 'flaskext.%s'], __name__) 26 | importer.install() 27 | 28 | 29 | setup() 30 | del setup 31 | -------------------------------------------------------------------------------- /NZBmegasearch/flask/globals.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | flask.globals 4 | ~~~~~~~~~~~~~ 5 | 6 | Defines all the global objects that are proxies to the current 7 | active context. 8 | 9 | :copyright: (c) 2011 by Armin Ronacher. 10 | :license: BSD, see LICENSE for more details. 11 | """ 12 | 13 | from functools import partial 14 | from werkzeug.local import LocalStack, LocalProxy 15 | 16 | 17 | def _lookup_object(name): 18 | top = _request_ctx_stack.top 19 | if top is None: 20 | raise RuntimeError('working outside of request context') 21 | return getattr(top, name) 22 | 23 | 24 | def _find_app(): 25 | top = _app_ctx_stack.top 26 | if top is None: 27 | raise RuntimeError('working outside of application context') 28 | return top.app 29 | 30 | # context locals 31 | _request_ctx_stack = LocalStack() 32 | _app_ctx_stack = LocalStack() 33 | current_app = LocalProxy(_find_app) 34 | request = LocalProxy(partial(_lookup_object, 'request')) 35 | session = LocalProxy(partial(_lookup_object, 'session')) 36 | g = LocalProxy(partial(_lookup_object, 'g')) 37 | -------------------------------------------------------------------------------- /NZBmegasearch/flask/logging.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | flask.logging 4 | ~~~~~~~~~~~~~ 5 | 6 | Implements the logging support for Flask. 7 | 8 | :copyright: (c) 2011 by Armin Ronacher. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | 12 | from __future__ import absolute_import 13 | 14 | from logging import getLogger, StreamHandler, Formatter, getLoggerClass, DEBUG 15 | 16 | 17 | def create_logger(app): 18 | """Creates a logger for the given application. This logger works 19 | similar to a regular Python logger but changes the effective logging 20 | level based on the application's debug flag. Furthermore this 21 | function also removes all attached handlers in case there was a 22 | logger with the log name before. 23 | """ 24 | Logger = getLoggerClass() 25 | 26 | class DebugLogger(Logger): 27 | def getEffectiveLevel(x): 28 | if x.level == 0 and app.debug: 29 | return DEBUG 30 | return Logger.getEffectiveLevel(x) 31 | 32 | class DebugHandler(StreamHandler): 33 | def emit(x, record): 34 | StreamHandler.emit(x, record) if app.debug else None 35 | 36 | handler = DebugHandler() 37 | handler.setLevel(DEBUG) 38 | handler.setFormatter(Formatter(app.debug_log_format)) 39 | logger = getLogger(app.logger_name) 40 | # just in case that was not a new logger, get rid of all the handlers 41 | # already attached to it. 42 | del logger.handlers[:] 43 | logger.__class__ = DebugLogger 44 | logger.addHandler(handler) 45 | return logger 46 | -------------------------------------------------------------------------------- /NZBmegasearch/flask/module.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | flask.module 4 | ~~~~~~~~~~~~ 5 | 6 | Implements a class that represents module blueprints. 7 | 8 | :copyright: (c) 2011 by Armin Ronacher. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | 12 | import os 13 | 14 | from .blueprints import Blueprint 15 | 16 | 17 | def blueprint_is_module(bp): 18 | """Used to figure out if something is actually a module""" 19 | return isinstance(bp, Module) 20 | 21 | 22 | class Module(Blueprint): 23 | """Deprecated module support. Until Flask 0.6 modules were a different 24 | name of the concept now available as blueprints in Flask. They are 25 | essentially doing the same but have some bad semantics for templates and 26 | static files that were fixed with blueprints. 27 | 28 | .. versionchanged:: 0.7 29 | Modules were deprecated in favor for blueprints. 30 | """ 31 | 32 | def __init__(self, import_name, name=None, url_prefix=None, 33 | static_path=None, subdomain=None): 34 | if name is None: 35 | assert '.' in import_name, 'name required if package name ' \ 36 | 'does not point to a submodule' 37 | name = import_name.rsplit('.', 1)[1] 38 | Blueprint.__init__(self, name, import_name, url_prefix=url_prefix, 39 | subdomain=subdomain, template_folder='templates') 40 | 41 | if os.path.isdir(os.path.join(self.root_path, 'static')): 42 | self._static_folder = 'static' 43 | -------------------------------------------------------------------------------- /NZBmegasearch/flask/session.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | flask.session 4 | ~~~~~~~~~~~~~ 5 | 6 | This module used to flask with the session global so we moved it 7 | over to flask.sessions 8 | 9 | :copyright: (c) 2011 by Armin Ronacher. 10 | :license: BSD, see LICENSE for more details. 11 | """ 12 | 13 | from warnings import warn 14 | 15 | warn(DeprecationWarning('please use flask.sessions instead')) 16 | 17 | from .sessions import SecureCookieSession, NullSession 18 | 19 | Session = SecureCookieSession 20 | _NullSession = NullSession 21 | -------------------------------------------------------------------------------- /NZBmegasearch/flask/signals.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | flask.signals 4 | ~~~~~~~~~~~~~ 5 | 6 | Implements signals based on blinker if available, otherwise 7 | falls silently back to a noop 8 | 9 | :copyright: (c) 2011 by Armin Ronacher. 10 | :license: BSD, see LICENSE for more details. 11 | """ 12 | signals_available = False 13 | try: 14 | from blinker import Namespace 15 | 16 | signals_available = True 17 | except ImportError: 18 | class Namespace(object): 19 | def signal(self, name, doc=None): 20 | return _FakeSignal(name, doc) 21 | 22 | class _FakeSignal(object): 23 | """If blinker is unavailable, create a fake class with the same 24 | interface that allows sending of signals but will fail with an 25 | error on anything else. Instead of doing anything on send, it 26 | will just ignore the arguments and do nothing instead. 27 | """ 28 | 29 | def __init__(self, name, doc=None): 30 | self.name = name 31 | self.__doc__ = doc 32 | 33 | def _fail(self, *args, **kwargs): 34 | raise RuntimeError('signalling support is unavailable ' 35 | 'because the blinker library is ' 36 | 'not installed.') 37 | 38 | send = lambda *a, **kw: None 39 | connect = disconnect = has_receivers_for = receivers_for = \ 40 | temporarily_connected_to = connected_to = _fail 41 | del _fail 42 | 43 | # the namespace for code signals. If you are not flask code, do 44 | # not put signals in here. Create your own namespace instead. 45 | _signals = Namespace() 46 | 47 | 48 | # core signals. For usage examples grep the sourcecode or consult 49 | # the API documentation in docs/api.rst as well as docs/signals.rst 50 | template_rendered = _signals.signal('template-rendered') 51 | request_started = _signals.signal('request-started') 52 | request_finished = _signals.signal('request-finished') 53 | request_tearing_down = _signals.signal('request-tearing-down') 54 | got_request_exception = _signals.signal('got-request-exception') 55 | appcontext_tearing_down = _signals.signal('appcontext-tearing-down') 56 | -------------------------------------------------------------------------------- /NZBmegasearch/jinja2/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | jinja2 4 | ~~~~~~ 5 | 6 | Jinja2 is a template engine written in pure Python. It provides a 7 | Django inspired non-XML syntax but supports inline expressions and 8 | an optional sandboxed environment. 9 | 10 | Nutshell 11 | -------- 12 | 13 | Here a small example of a Jinja2 template:: 14 | 15 | {% extends 'base.html' %} 16 | {% block title %}Memberlist{% endblock %} 17 | {% block content %} 18 | 23 | {% endblock %} 24 | 25 | 26 | :copyright: (c) 2010 by the Jinja Team. 27 | :license: BSD, see LICENSE for more details. 28 | """ 29 | __docformat__ = 'restructuredtext en' 30 | __version__ = '2.6' 31 | # high level interface 32 | from jinja2.environment import Environment, Template 33 | 34 | # loaders 35 | from jinja2.loaders import BaseLoader, FileSystemLoader, PackageLoader, \ 36 | DictLoader, FunctionLoader, PrefixLoader, ChoiceLoader, \ 37 | ModuleLoader 38 | 39 | # bytecode caches 40 | from jinja2.bccache import BytecodeCache, FileSystemBytecodeCache, \ 41 | MemcachedBytecodeCache 42 | 43 | # undefined types 44 | from jinja2.runtime import Undefined, DebugUndefined, StrictUndefined 45 | 46 | # exceptions 47 | from jinja2.exceptions import TemplateError, UndefinedError, \ 48 | TemplateNotFound, TemplatesNotFound, TemplateSyntaxError, \ 49 | TemplateAssertionError 50 | 51 | # decorators and public utilities 52 | from jinja2.filters import environmentfilter, contextfilter, \ 53 | evalcontextfilter 54 | from jinja2.utils import Markup, escape, clear_caches, \ 55 | environmentfunction, evalcontextfunction, contextfunction, \ 56 | is_undefined 57 | 58 | __all__ = [ 59 | 'Environment', 'Template', 'BaseLoader', 'FileSystemLoader', 60 | 'PackageLoader', 'DictLoader', 'FunctionLoader', 'PrefixLoader', 61 | 'ChoiceLoader', 'BytecodeCache', 'FileSystemBytecodeCache', 62 | 'MemcachedBytecodeCache', 'Undefined', 'DebugUndefined', 63 | 'StrictUndefined', 'TemplateError', 'UndefinedError', 'TemplateNotFound', 64 | 'TemplatesNotFound', 'TemplateSyntaxError', 'TemplateAssertionError', 65 | 'ModuleLoader', 'environmentfilter', 'contextfilter', 'Markup', 'escape', 66 | 'environmentfunction', 'contextfunction', 'clear_caches', 'is_undefined', 67 | 'evalcontextfilter', 'evalcontextfunction' 68 | ] 69 | -------------------------------------------------------------------------------- /NZBmegasearch/jinja2/_debugsupport.c: -------------------------------------------------------------------------------- 1 | /** 2 | * jinja2._debugsupport 3 | * ~~~~~~~~~~~~~~~~~~~~ 4 | * 5 | * C implementation of `tb_set_next`. 6 | * 7 | * :copyright: (c) 2010 by the Jinja Team. 8 | * :license: BSD. 9 | */ 10 | 11 | #include 12 | 13 | 14 | static PyObject* 15 | tb_set_next(PyObject *self, PyObject *args) 16 | { 17 | PyTracebackObject *tb, *old; 18 | PyObject *next; 19 | 20 | if (!PyArg_ParseTuple(args, "O!O:tb_set_next", &PyTraceBack_Type, &tb, &next)) 21 | return NULL; 22 | if (next == Py_None) 23 | next = NULL; 24 | else if (!PyTraceBack_Check(next)) { 25 | PyErr_SetString(PyExc_TypeError, 26 | "tb_set_next arg 2 must be traceback or None"); 27 | return NULL; 28 | } 29 | else 30 | Py_INCREF(next); 31 | 32 | old = tb->tb_next; 33 | tb->tb_next = (PyTracebackObject*)next; 34 | Py_XDECREF(old); 35 | 36 | Py_INCREF(Py_None); 37 | return Py_None; 38 | } 39 | 40 | static PyMethodDef module_methods[] = { 41 | {"tb_set_next", (PyCFunction)tb_set_next, METH_VARARGS, 42 | "Set the tb_next member of a traceback object."}, 43 | {NULL, NULL, 0, NULL} /* Sentinel */ 44 | }; 45 | 46 | 47 | #if PY_MAJOR_VERSION < 3 48 | 49 | #ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ 50 | #define PyMODINIT_FUNC void 51 | #endif 52 | PyMODINIT_FUNC 53 | init_debugsupport(void) 54 | { 55 | Py_InitModule3("jinja2._debugsupport", module_methods, ""); 56 | } 57 | 58 | #else /* Python 3.x module initialization */ 59 | 60 | static struct PyModuleDef module_definition = { 61 | PyModuleDef_HEAD_INIT, 62 | "jinja2._debugsupport", 63 | NULL, 64 | -1, 65 | module_methods, 66 | NULL, 67 | NULL, 68 | NULL, 69 | NULL 70 | }; 71 | 72 | PyMODINIT_FUNC 73 | PyInit__debugsupport(void) 74 | { 75 | return PyModule_Create(&module_definition); 76 | } 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /NZBmegasearch/jinja2/_markupsafe/_bundle.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | jinja2._markupsafe._bundle 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | This script pulls in markupsafe from a source folder and 7 | bundles it with Jinja2. It does not pull in the speedups 8 | module though. 9 | 10 | :copyright: Copyright 2010 by the Jinja team, see AUTHORS. 11 | :license: BSD, see LICENSE for details. 12 | """ 13 | import sys 14 | import os 15 | import re 16 | 17 | 18 | def rewrite_imports(lines): 19 | for idx, line in enumerate(lines): 20 | new_line = re.sub(r'(import|from)\s+markupsafe\b', 21 | r'\1 jinja2._markupsafe', line) 22 | if new_line != line: 23 | lines[idx] = new_line 24 | 25 | 26 | def main(): 27 | if len(sys.argv) != 2: 28 | print 'error: only argument is path to markupsafe' 29 | sys.exit(1) 30 | basedir = os.path.dirname(__file__) 31 | markupdir = sys.argv[1] 32 | for filename in os.listdir(markupdir): 33 | if filename.endswith('.py'): 34 | f = open(os.path.join(markupdir, filename)) 35 | try: 36 | lines = list(f) 37 | finally: 38 | f.close() 39 | rewrite_imports(lines) 40 | f = open(os.path.join(basedir, filename), 'w') 41 | try: 42 | for line in lines: 43 | f.write(line) 44 | finally: 45 | f.close() 46 | 47 | 48 | if __name__ == '__main__': 49 | main() 50 | -------------------------------------------------------------------------------- /NZBmegasearch/jinja2/_markupsafe/_native.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | markupsafe._native 4 | ~~~~~~~~~~~~~~~~~~ 5 | 6 | Native Python implementation the C module is not compiled. 7 | 8 | :copyright: (c) 2010 by Armin Ronacher. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | from jinja2._markupsafe import Markup 12 | 13 | 14 | def escape(s): 15 | """Convert the characters &, <, >, ' and " in string s to HTML-safe 16 | sequences. Use this if you need to display text that might contain 17 | such characters in HTML. Marks return value as markup string. 18 | """ 19 | if hasattr(s, '__html__'): 20 | return s.__html__() 21 | return Markup(unicode(s) 22 | .replace('&', '&') 23 | .replace('>', '>') 24 | .replace('<', '<') 25 | .replace("'", ''') 26 | .replace('"', '"') 27 | ) 28 | 29 | 30 | def escape_silent(s): 31 | """Like :func:`escape` but converts `None` into an empty 32 | markup string. 33 | """ 34 | if s is None: 35 | return Markup() 36 | return escape(s) 37 | 38 | 39 | def soft_unicode(s): 40 | """Make a string unicode if it isn't already. That way a markup 41 | string is not converted back to unicode. 42 | """ 43 | if not isinstance(s, unicode): 44 | s = unicode(s) 45 | return s 46 | -------------------------------------------------------------------------------- /NZBmegasearch/jinja2/_markupsafe/tests.py: -------------------------------------------------------------------------------- 1 | import gc 2 | import unittest 3 | from jinja2._markupsafe import Markup, escape, escape_silent 4 | 5 | 6 | class MarkupTestCase(unittest.TestCase): 7 | def test_markup_operations(self): 8 | # adding two strings should escape the unsafe one 9 | unsafe = '' 10 | safe = Markup('username') 11 | assert unsafe + safe == unicode(escape(unsafe)) + unicode(safe) 12 | 13 | # string interpolations are safe to use too 14 | assert Markup('%s') % '' == \ 15 | '<bad user>' 16 | assert Markup('%(username)s') % { 17 | 'username': '' 18 | } == '<bad user>' 19 | 20 | # an escaped object is markup too 21 | assert type(Markup('foo') + 'bar') is Markup 22 | 23 | # and it implements __html__ by returning itself 24 | x = Markup("foo") 25 | assert x.__html__() is x 26 | 27 | # it also knows how to treat __html__ objects 28 | class Foo(object): 29 | def __html__(self): 30 | return 'awesome' 31 | 32 | def __unicode__(self): 33 | return 'awesome' 34 | 35 | assert Markup(Foo()) == 'awesome' 36 | assert Markup('%s') % Foo() == \ 37 | 'awesome' 38 | 39 | # escaping and unescaping 40 | assert escape('"<>&\'') == '"<>&'' 41 | assert Markup("Foo & Bar").striptags() == "Foo & Bar" 42 | assert Markup("<test>").unescape() == "" 43 | 44 | def test_all_set(self): 45 | import jinja2._markupsafe as markup 46 | 47 | for item in markup.__all__: 48 | getattr(markup, item) 49 | 50 | def test_escape_silent(self): 51 | assert escape_silent(None) == Markup() 52 | assert escape(None) == Markup(None) 53 | assert escape_silent('') == Markup(u'<foo>') 54 | 55 | 56 | class MarkupLeakTestCase(unittest.TestCase): 57 | def test_markup_leaks(self): 58 | counts = set() 59 | for count in xrange(20): 60 | for item in xrange(1000): 61 | escape("foo") 62 | escape("") 63 | escape(u"foo") 64 | escape(u"") 65 | counts.add(len(gc.get_objects())) 66 | assert len(counts) == 1, 'ouch, c extension seems to leak objects' 67 | 68 | 69 | def suite(): 70 | suite = unittest.TestSuite() 71 | suite.addTest(unittest.makeSuite(MarkupTestCase)) 72 | 73 | # this test only tests the c extension 74 | if not hasattr(escape, 'func_code'): 75 | suite.addTest(unittest.makeSuite(MarkupLeakTestCase)) 76 | 77 | return suite 78 | 79 | 80 | if __name__ == '__main__': 81 | unittest.main(defaultTest='suite') 82 | -------------------------------------------------------------------------------- /NZBmegasearch/jinja2/constants.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | jinja.constants 4 | ~~~~~~~~~~~~~~~ 5 | 6 | Various constants. 7 | 8 | :copyright: (c) 2010 by the Jinja Team. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | 12 | 13 | #: list of lorem ipsum words used by the lipsum() helper function 14 | LOREM_IPSUM_WORDS = u'''\ 15 | a ac accumsan ad adipiscing aenean aliquam aliquet amet ante aptent arcu at 16 | auctor augue bibendum blandit class commodo condimentum congue consectetuer 17 | consequat conubia convallis cras cubilia cum curabitur curae cursus dapibus 18 | diam dictum dictumst dignissim dis dolor donec dui duis egestas eget eleifend 19 | elementum elit enim erat eros est et etiam eu euismod facilisi facilisis fames 20 | faucibus felis fermentum feugiat fringilla fusce gravida habitant habitasse hac 21 | hendrerit hymenaeos iaculis id imperdiet in inceptos integer interdum ipsum 22 | justo lacinia lacus laoreet lectus leo libero ligula litora lobortis lorem 23 | luctus maecenas magna magnis malesuada massa mattis mauris metus mi molestie 24 | mollis montes morbi mus nam nascetur natoque nec neque netus nibh nisi nisl non 25 | nonummy nostra nulla nullam nunc odio orci ornare parturient pede pellentesque 26 | penatibus per pharetra phasellus placerat platea porta porttitor posuere 27 | potenti praesent pretium primis proin pulvinar purus quam quis quisque rhoncus 28 | ridiculus risus rutrum sagittis sapien scelerisque sed sem semper senectus sit 29 | sociis sociosqu sodales sollicitudin suscipit suspendisse taciti tellus tempor 30 | tempus tincidunt torquent tortor tristique turpis ullamcorper ultrices 31 | ultricies urna ut varius vehicula vel velit venenatis vestibulum vitae vivamus 32 | viverra volutpat vulputate''' 33 | -------------------------------------------------------------------------------- /NZBmegasearch/jinja2/defaults.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | jinja2.defaults 4 | ~~~~~~~~~~~~~~~ 5 | 6 | Jinja default filters and tags. 7 | 8 | :copyright: (c) 2010 by the Jinja Team. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | from jinja2.utils import generate_lorem_ipsum, Cycler, Joiner 12 | 13 | 14 | # defaults for the parser / lexer 15 | BLOCK_START_STRING = '{%' 16 | BLOCK_END_STRING = '%}' 17 | VARIABLE_START_STRING = '{{' 18 | VARIABLE_END_STRING = '}}' 19 | COMMENT_START_STRING = '{#' 20 | COMMENT_END_STRING = '#}' 21 | LINE_STATEMENT_PREFIX = None 22 | LINE_COMMENT_PREFIX = None 23 | TRIM_BLOCKS = False 24 | NEWLINE_SEQUENCE = '\n' 25 | 26 | 27 | # default filters, tests and namespace 28 | from jinja2.filters import FILTERS as DEFAULT_FILTERS 29 | from jinja2.tests import TESTS as DEFAULT_TESTS 30 | 31 | DEFAULT_NAMESPACE = { 32 | 'range': xrange, 33 | 'dict': lambda **kw: kw, 34 | 'lipsum': generate_lorem_ipsum, 35 | 'cycler': Cycler, 36 | 'joiner': Joiner 37 | } 38 | 39 | 40 | # export all constants 41 | __all__ = tuple(x for x in locals().keys() if x.isupper()) 42 | -------------------------------------------------------------------------------- /NZBmegasearch/jinja2/optimizer.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | jinja2.optimizer 4 | ~~~~~~~~~~~~~~~~ 5 | 6 | The jinja optimizer is currently trying to constant fold a few expressions 7 | and modify the AST in place so that it should be easier to evaluate it. 8 | 9 | Because the AST does not contain all the scoping information and the 10 | compiler has to find that out, we cannot do all the optimizations we 11 | want. For example loop unrolling doesn't work because unrolled loops would 12 | have a different scoping. 13 | 14 | The solution would be a second syntax tree that has the scoping rules stored. 15 | 16 | :copyright: (c) 2010 by the Jinja Team. 17 | :license: BSD. 18 | """ 19 | from jinja2 import nodes 20 | from jinja2.visitor import NodeTransformer 21 | 22 | 23 | def optimize(node, environment): 24 | """The context hint can be used to perform an static optimization 25 | based on the context given.""" 26 | optimizer = Optimizer(environment) 27 | return optimizer.visit(node) 28 | 29 | 30 | class Optimizer(NodeTransformer): 31 | def __init__(self, environment): 32 | self.environment = environment 33 | 34 | def visit_If(self, node): 35 | """Eliminate dead code.""" 36 | # do not optimize ifs that have a block inside so that it doesn't 37 | # break super(). 38 | if node.find(nodes.Block) is not None: 39 | return self.generic_visit(node) 40 | try: 41 | val = self.visit(node.test).as_const() 42 | except nodes.Impossible: 43 | return self.generic_visit(node) 44 | if val: 45 | body = node.body 46 | else: 47 | body = node.else_ 48 | result = [] 49 | for node in body: 50 | result.extend(self.visit_list(node)) 51 | return result 52 | 53 | def fold(self, node): 54 | """Do constant folding.""" 55 | node = self.generic_visit(node) 56 | try: 57 | return nodes.Const.from_untrusted(node.as_const(), 58 | lineno=node.lineno, 59 | environment=self.environment) 60 | except nodes.Impossible: 61 | return node 62 | 63 | visit_Add = visit_Sub = visit_Mul = visit_Div = visit_FloorDiv = \ 64 | visit_Pow = visit_Mod = visit_And = visit_Or = visit_Pos = visit_Neg = \ 65 | visit_Not = visit_Compare = visit_Getitem = visit_Getattr = visit_Call = \ 66 | visit_Filter = visit_Test = visit_CondExpr = fold 67 | del fold 68 | -------------------------------------------------------------------------------- /NZBmegasearch/jinja2/testsuite/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | jinja2.testsuite 4 | ~~~~~~~~~~~~~~~~ 5 | 6 | All the unittests of Jinja2. These tests can be executed by 7 | either running run-tests.py using multiple Python versions at 8 | the same time. 9 | 10 | :copyright: (c) 2010 by the Jinja Team. 11 | :license: BSD, see LICENSE for more details. 12 | """ 13 | import os 14 | import re 15 | import sys 16 | import unittest 17 | from traceback import format_exception 18 | from jinja2 import loaders 19 | 20 | here = os.path.dirname(os.path.abspath(__file__)) 21 | 22 | dict_loader = loaders.DictLoader({ 23 | 'justdict.html': 'FOO' 24 | }) 25 | package_loader = loaders.PackageLoader('jinja2.testsuite.res', 'templates') 26 | filesystem_loader = loaders.FileSystemLoader(here + '/res/templates') 27 | function_loader = loaders.FunctionLoader({'justfunction.html': 'FOO'}.get) 28 | choice_loader = loaders.ChoiceLoader([dict_loader, package_loader]) 29 | prefix_loader = loaders.PrefixLoader({ 30 | 'a': filesystem_loader, 31 | 'b': dict_loader 32 | }) 33 | 34 | 35 | class JinjaTestCase(unittest.TestCase): 36 | ### use only these methods for testing. If you need standard 37 | ### unittest method, wrap them! 38 | 39 | def setup(self): 40 | pass 41 | 42 | def teardown(self): 43 | pass 44 | 45 | def setUp(self): 46 | self.setup() 47 | 48 | def tearDown(self): 49 | self.teardown() 50 | 51 | def assert_equal(self, a, b): 52 | return self.assertEqual(a, b) 53 | 54 | def assert_raises(self, *args, **kwargs): 55 | return self.assertRaises(*args, **kwargs) 56 | 57 | def assert_traceback_matches(self, callback, expected_tb): 58 | try: 59 | callback() 60 | except Exception, e: 61 | tb = format_exception(*sys.exc_info()) 62 | if re.search(expected_tb.strip(), ''.join(tb)) is None: 63 | raise self.fail('Traceback did not match:\n\n%s\nexpected:\n%s' 64 | % (''.join(tb), expected_tb)) 65 | else: 66 | self.fail('Expected exception') 67 | 68 | 69 | def suite(): 70 | from jinja2.testsuite import ext, filters, tests, core_tags, \ 71 | loader, inheritance, imports, lexnparse, security, api, \ 72 | regression, debug, utils, doctests 73 | 74 | suite = unittest.TestSuite() 75 | suite.addTest(ext.suite()) 76 | suite.addTest(filters.suite()) 77 | suite.addTest(tests.suite()) 78 | suite.addTest(core_tags.suite()) 79 | suite.addTest(loader.suite()) 80 | suite.addTest(inheritance.suite()) 81 | suite.addTest(imports.suite()) 82 | suite.addTest(lexnparse.suite()) 83 | suite.addTest(security.suite()) 84 | suite.addTest(api.suite()) 85 | suite.addTest(regression.suite()) 86 | suite.addTest(debug.suite()) 87 | suite.addTest(utils.suite()) 88 | 89 | # doctests will not run on python 3 currently. Too many issues 90 | # with that, do not test that on that platform. 91 | if sys.version_info < (3, 0): 92 | suite.addTest(doctests.suite()) 93 | 94 | return suite 95 | -------------------------------------------------------------------------------- /NZBmegasearch/jinja2/testsuite/debug.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | jinja2.testsuite.debug 4 | ~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Tests the debug system. 7 | 8 | :copyright: (c) 2010 by the Jinja Team. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | import sys 12 | import unittest 13 | 14 | from jinja2.testsuite import JinjaTestCase, filesystem_loader 15 | 16 | from jinja2 import Environment, TemplateSyntaxError 17 | 18 | env = Environment(loader=filesystem_loader) 19 | 20 | 21 | class DebugTestCase(JinjaTestCase): 22 | if sys.version_info[:2] != (2, 4): 23 | def test_runtime_error(self): 24 | def test(): 25 | tmpl.render(fail=lambda: 1 / 0) 26 | 27 | tmpl = env.get_template('broken.html') 28 | self.assert_traceback_matches(test, r''' 29 | File ".*?broken.html", line 2, in (top-level template code|) 30 | \{\{ fail\(\) \}\} 31 | File ".*?debug.pyc?", line \d+, in 32 | tmpl\.render\(fail=lambda: 1 / 0\) 33 | ZeroDivisionError: (int(eger)? )?division (or modulo )?by zero 34 | ''') 35 | 36 | def test_syntax_error(self): 37 | # XXX: the .*? is necessary for python3 which does not hide 38 | # some of the stack frames we don't want to show. Not sure 39 | # what's up with that, but that is not that critical. Should 40 | # be fixed though. 41 | self.assert_traceback_matches(lambda: env.get_template('syntaxerror.html'), r'''(?sm) 42 | File ".*?syntaxerror.html", line 4, in (template|) 43 | \{% endif %\}.*? 44 | (jinja2\.exceptions\.)?TemplateSyntaxError: Encountered unknown tag 'endif'. Jinja was looking for the following tags: 'endfor' or 'else'. The innermost block that needs to be closed is 'for'. 45 | ''') 46 | 47 | def test_regular_syntax_error(self): 48 | def test(): 49 | raise TemplateSyntaxError('wtf', 42) 50 | 51 | self.assert_traceback_matches(test, r''' 52 | File ".*debug.pyc?", line \d+, in test 53 | raise TemplateSyntaxError\('wtf', 42\) 54 | (jinja2\.exceptions\.)?TemplateSyntaxError: wtf 55 | line 42''') 56 | 57 | 58 | def suite(): 59 | suite = unittest.TestSuite() 60 | suite.addTest(unittest.makeSuite(DebugTestCase)) 61 | return suite 62 | -------------------------------------------------------------------------------- /NZBmegasearch/jinja2/testsuite/doctests.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | jinja2.testsuite.doctests 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | The doctests. Collects all tests we want to test from 7 | the Jinja modules. 8 | 9 | :copyright: (c) 2010 by the Jinja Team. 10 | :license: BSD, see LICENSE for more details. 11 | """ 12 | import unittest 13 | import doctest 14 | 15 | 16 | def suite(): 17 | from jinja2 import utils, sandbox, runtime, meta, loaders, \ 18 | ext, environment, bccache, nodes 19 | 20 | suite = unittest.TestSuite() 21 | suite.addTest(doctest.DocTestSuite(utils)) 22 | suite.addTest(doctest.DocTestSuite(sandbox)) 23 | suite.addTest(doctest.DocTestSuite(runtime)) 24 | suite.addTest(doctest.DocTestSuite(meta)) 25 | suite.addTest(doctest.DocTestSuite(loaders)) 26 | suite.addTest(doctest.DocTestSuite(ext)) 27 | suite.addTest(doctest.DocTestSuite(environment)) 28 | suite.addTest(doctest.DocTestSuite(bccache)) 29 | suite.addTest(doctest.DocTestSuite(nodes)) 30 | return suite 31 | -------------------------------------------------------------------------------- /NZBmegasearch/jinja2/testsuite/res/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/jinja2/testsuite/res/__init__.py -------------------------------------------------------------------------------- /NZBmegasearch/jinja2/testsuite/res/templates/broken.html: -------------------------------------------------------------------------------- 1 | Before 2 | {{ fail() }} 3 | After 4 | -------------------------------------------------------------------------------- /NZBmegasearch/jinja2/testsuite/res/templates/foo/test.html: -------------------------------------------------------------------------------- 1 | FOO 2 | -------------------------------------------------------------------------------- /NZBmegasearch/jinja2/testsuite/res/templates/syntaxerror.html: -------------------------------------------------------------------------------- 1 | Foo 2 | {% for item in broken %} 3 | ... 4 | {% endif %} 5 | -------------------------------------------------------------------------------- /NZBmegasearch/jinja2/testsuite/res/templates/test.html: -------------------------------------------------------------------------------- 1 | BAR 2 | -------------------------------------------------------------------------------- /NZBmegasearch/jinja2/testsuite/tests.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | jinja2.testsuite.tests 4 | ~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Who tests the tests? 7 | 8 | :copyright: (c) 2010 by the Jinja Team. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | import unittest 12 | from jinja2.testsuite import JinjaTestCase 13 | 14 | from jinja2 import Markup, Environment 15 | 16 | env = Environment() 17 | 18 | 19 | class TestsTestCase(JinjaTestCase): 20 | def test_defined(self): 21 | tmpl = env.from_string('{{ missing is defined }}|{{ true is defined }}') 22 | assert tmpl.render() == 'False|True' 23 | 24 | def test_even(self): 25 | tmpl = env.from_string('''{{ 1 is even }}|{{ 2 is even }}''') 26 | assert tmpl.render() == 'False|True' 27 | 28 | def test_odd(self): 29 | tmpl = env.from_string('''{{ 1 is odd }}|{{ 2 is odd }}''') 30 | assert tmpl.render() == 'True|False' 31 | 32 | def test_lower(self): 33 | tmpl = env.from_string('''{{ "foo" is lower }}|{{ "FOO" is lower }}''') 34 | assert tmpl.render() == 'True|False' 35 | 36 | def test_typechecks(self): 37 | tmpl = env.from_string(''' 38 | {{ 42 is undefined }} 39 | {{ 42 is defined }} 40 | {{ 42 is none }} 41 | {{ none is none }} 42 | {{ 42 is number }} 43 | {{ 42 is string }} 44 | {{ "foo" is string }} 45 | {{ "foo" is sequence }} 46 | {{ [1] is sequence }} 47 | {{ range is callable }} 48 | {{ 42 is callable }} 49 | {{ range(5) is iterable }} 50 | {{ {} is mapping }} 51 | {{ mydict is mapping }} 52 | {{ [] is mapping }} 53 | ''') 54 | 55 | class MyDict(dict): 56 | pass 57 | 58 | assert tmpl.render(mydict=MyDict()).split() == [ 59 | 'False', 'True', 'False', 'True', 'True', 'False', 60 | 'True', 'True', 'True', 'True', 'False', 'True', 61 | 'True', 'True', 'False' 62 | ] 63 | 64 | def test_sequence(self): 65 | tmpl = env.from_string( 66 | '{{ [1, 2, 3] is sequence }}|' 67 | '{{ "foo" is sequence }}|' 68 | '{{ 42 is sequence }}' 69 | ) 70 | assert tmpl.render() == 'True|True|False' 71 | 72 | def test_upper(self): 73 | tmpl = env.from_string('{{ "FOO" is upper }}|{{ "foo" is upper }}') 74 | assert tmpl.render() == 'True|False' 75 | 76 | def test_sameas(self): 77 | tmpl = env.from_string('{{ foo is sameas false }}|' 78 | '{{ 0 is sameas false }}') 79 | assert tmpl.render(foo=False) == 'True|False' 80 | 81 | def test_no_paren_for_arg1(self): 82 | tmpl = env.from_string('{{ foo is sameas none }}') 83 | assert tmpl.render(foo=None) == 'True' 84 | 85 | def test_escaped(self): 86 | env = Environment(autoescape=True) 87 | tmpl = env.from_string('{{ x is escaped }}|{{ y is escaped }}') 88 | assert tmpl.render(x='foo', y=Markup('foo')) == 'False|True' 89 | 90 | 91 | def suite(): 92 | suite = unittest.TestSuite() 93 | suite.addTest(unittest.makeSuite(TestsTestCase)) 94 | return suite 95 | -------------------------------------------------------------------------------- /NZBmegasearch/jinja2/testsuite/utils.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | jinja2.testsuite.utils 4 | ~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Tests utilities jinja uses. 7 | 8 | :copyright: (c) 2010 by the Jinja Team. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | import gc 12 | import unittest 13 | 14 | import pickle 15 | 16 | from jinja2.testsuite import JinjaTestCase 17 | 18 | from jinja2.utils import LRUCache, escape, object_type_repr 19 | 20 | 21 | class LRUCacheTestCase(JinjaTestCase): 22 | def test_simple(self): 23 | d = LRUCache(3) 24 | d["a"] = 1 25 | d["b"] = 2 26 | d["c"] = 3 27 | d["a"] 28 | d["d"] = 4 29 | assert len(d) == 3 30 | assert 'a' in d and 'c' in d and 'd' in d and 'b' not in d 31 | 32 | def test_pickleable(self): 33 | cache = LRUCache(2) 34 | cache["foo"] = 42 35 | cache["bar"] = 23 36 | cache["foo"] 37 | 38 | for protocol in range(3): 39 | copy = pickle.loads(pickle.dumps(cache, protocol)) 40 | assert copy.capacity == cache.capacity 41 | assert copy._mapping == cache._mapping 42 | assert copy._queue == cache._queue 43 | 44 | 45 | class HelpersTestCase(JinjaTestCase): 46 | def test_object_type_repr(self): 47 | class X(object): 48 | pass 49 | 50 | self.assert_equal(object_type_repr(42), 'int object') 51 | self.assert_equal(object_type_repr([]), 'list object') 52 | self.assert_equal(object_type_repr(X()), 53 | 'jinja2.testsuite.utils.X object') 54 | self.assert_equal(object_type_repr(None), 'None') 55 | self.assert_equal(object_type_repr(Ellipsis), 'Ellipsis') 56 | 57 | 58 | class MarkupLeakTestCase(JinjaTestCase): 59 | def test_markup_leaks(self): 60 | counts = set() 61 | for count in xrange(20): 62 | for item in xrange(1000): 63 | escape("foo") 64 | escape("") 65 | escape(u"foo") 66 | escape(u"") 67 | counts.add(len(gc.get_objects())) 68 | assert len(counts) == 1, 'ouch, c extension seems to leak objects' 69 | 70 | 71 | def suite(): 72 | suite = unittest.TestSuite() 73 | suite.addTest(unittest.makeSuite(LRUCacheTestCase)) 74 | suite.addTest(unittest.makeSuite(HelpersTestCase)) 75 | 76 | # this test only tests the c extension 77 | if not hasattr(escape, 'func_code'): 78 | suite.addTest(unittest.makeSuite(MarkupLeakTestCase)) 79 | 80 | return suite 81 | -------------------------------------------------------------------------------- /NZBmegasearch/jinja2/visitor.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | jinja2.visitor 4 | ~~~~~~~~~~~~~~ 5 | 6 | This module implements a visitor for the nodes. 7 | 8 | :copyright: (c) 2010 by the Jinja Team. 9 | :license: BSD. 10 | """ 11 | from jinja2.nodes import Node 12 | 13 | 14 | class NodeVisitor(object): 15 | """Walks the abstract syntax tree and call visitor functions for every 16 | node found. The visitor functions may return values which will be 17 | forwarded by the `visit` method. 18 | 19 | Per default the visitor functions for the nodes are ``'visit_'`` + 20 | class name of the node. So a `TryFinally` node visit function would 21 | be `visit_TryFinally`. This behavior can be changed by overriding 22 | the `get_visitor` function. If no visitor function exists for a node 23 | (return value `None`) the `generic_visit` visitor is used instead. 24 | """ 25 | 26 | def get_visitor(self, node): 27 | """Return the visitor function for this node or `None` if no visitor 28 | exists for this node. In that case the generic visit function is 29 | used instead. 30 | """ 31 | method = 'visit_' + node.__class__.__name__ 32 | return getattr(self, method, None) 33 | 34 | def visit(self, node, *args, **kwargs): 35 | """Visit a node.""" 36 | f = self.get_visitor(node) 37 | if f is not None: 38 | return f(node, *args, **kwargs) 39 | return self.generic_visit(node, *args, **kwargs) 40 | 41 | def generic_visit(self, node, *args, **kwargs): 42 | """Called if no explicit visitor function exists for a node.""" 43 | for node in node.iter_child_nodes(): 44 | self.visit(node, *args, **kwargs) 45 | 46 | 47 | class NodeTransformer(NodeVisitor): 48 | """Walks the abstract syntax tree and allows modifications of nodes. 49 | 50 | The `NodeTransformer` will walk the AST and use the return value of the 51 | visitor functions to replace or remove the old node. If the return 52 | value of the visitor function is `None` the node will be removed 53 | from the previous location otherwise it's replaced with the return 54 | value. The return value may be the original node in which case no 55 | replacement takes place. 56 | """ 57 | 58 | def generic_visit(self, node, *args, **kwargs): 59 | for field, old_value in node.iter_fields(): 60 | if isinstance(old_value, list): 61 | new_values = [] 62 | for value in old_value: 63 | if isinstance(value, Node): 64 | value = self.visit(value, *args, **kwargs) 65 | if value is None: 66 | continue 67 | elif not isinstance(value, Node): 68 | new_values.extend(value) 69 | continue 70 | new_values.append(value) 71 | old_value[:] = new_values 72 | elif isinstance(old_value, Node): 73 | new_node = self.visit(old_value, *args, **kwargs) 74 | if new_node is None: 75 | delattr(node, field) 76 | else: 77 | setattr(node, field, new_node) 78 | return node 79 | 80 | def visit_list(self, node, *args, **kwargs): 81 | """As transformers may return lists in some places this method 82 | can be used to enforce a list as return value. 83 | """ 84 | rv = self.visit(node, *args, **kwargs) 85 | if not isinstance(rv, list): 86 | rv = [rv] 87 | return rv 88 | -------------------------------------------------------------------------------- /NZBmegasearch/large_server/nginx.conf: -------------------------------------------------------------------------------- 1 | daemon off; # run in the foreground so supervisord can look after it 2 | worker_processes 2; 3 | 4 | user nobody nogroup; 5 | pid /tmp/nginx.pid; 6 | error_log /tmp/nginx.error.log; 7 | 8 | events { 9 | worker_connections 1024; 10 | accept_mutex off; 11 | } 12 | 13 | http { 14 | include mime.types; 15 | default_type application/octet-stream; 16 | access_log /tmp/nginx.access.log combined; 17 | sendfile on; 18 | 19 | upstream app_server { 20 | server unix:/tmp/gunicorn.sock fail_timeout=0; 21 | # For a TCP configuration: 22 | # server 192.168.0.7:8000 fail_timeout=0; 23 | } 24 | 25 | server { 26 | listen 443 ssl; 27 | listen 80 default_server; 28 | 29 | ssl_certificate /opt/usntssearch/NZBmegasearch/certificates/server.crt; 30 | ssl_certificate_key /opt/usntssearch/NZBmegasearch/certificates/server.key; 31 | 32 | 33 | client_max_body_size 4G; 34 | server_name _; 35 | 36 | keepalive_timeout 5; 37 | 38 | # path for static files 39 | root /opt/usntssearch/NZBmegasearch/static/; 40 | 41 | location / { 42 | # checks for static file, if not found proxy to app 43 | try_files $uri @proxy_to_app; 44 | } 45 | 46 | # Proxy download 47 | location ~* ^/warpme/http(s?)://(.*?)/(.*) { 48 | resolver 8.8.8.8; 49 | 50 | # Do not allow people to mess with this location directly 51 | # Only internal redirects are allowed 52 | internal; 53 | 54 | # Location-specific logging 55 | access_log /tmp/internal_redirect.access.log combined; 56 | error_log /tmp/internal_redirect.error.log warn; 57 | 58 | # Extract download url from the request 59 | set $download_uri $3; 60 | set $download_host $2; 61 | set $download_protocol $1; 62 | 63 | # Compose download url 64 | set $download_url http$download_protocol://$download_host/$download_uri?$args; 65 | 66 | # Set download request headers 67 | proxy_set_header Host $download_host; 68 | proxy_set_header Authorization ''; 69 | 70 | #~ debug purposes 71 | #~ add_header DBG_prot '$download_protocol'; 72 | #~ add_header DBG_host '$download_host'; 73 | #~ add_header DBG_uri '$download_uri'; 74 | #~ add_header DBG_fullurl '$download_url'; 75 | #~ add_header DBG_args '$args'; 76 | 77 | # Do not touch local disks when proxying 78 | # content to clients 79 | proxy_max_temp_file_size 0; 80 | 81 | # Download the file and send it to client 82 | proxy_pass $download_url; 83 | 84 | 85 | } 86 | 87 | 88 | location @proxy_to_app { 89 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 90 | proxy_set_header Host $http_host; 91 | proxy_redirect off; 92 | 93 | proxy_pass http://app_server; 94 | } 95 | 96 | error_page 500 502 503 504 /500.html; 97 | location = /500.html { 98 | root /opt/usntssearch/NZBmegasearch/static/; 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /NZBmegasearch/large_server/nginx_install.md: -------------------------------------------------------------------------------- 1 | ## How to install NZBMegasearch + NGINX + GUNICORN 2 | 3 | This document explains how to install NZBMegasearch for handling heavy traffic by combining with nginx and Gunicorn. 4 | 5 | 6 | It has been heavily tested by large quantity of users in the last months. 7 | 8 | Who need this? 9 | 10 | * moderate to high traffic websites 11 | * who wants an exact replica of mega.nzbx.co ;) 12 | 13 | --- 14 | 15 | ### Content 16 | 17 | * STEP 0: Tools needed 18 | * STEP 1: Installation and configuration 19 | * STEP 2: All systems ready 20 | 21 | --- 22 | 23 | ### STEP 0: Tools needed 24 | 25 | A linux system. You also need: 26 | 27 | * nginx and supervisord: `$ sudo apt-get install nginx supervisor` 28 | * gunicorn: `$ sudo easy_install gunicorn` 29 | 30 | --- 31 | 32 | ### STEP 1: Installation and configuration 33 | 34 | * Install NZBMegasearch (**not as root**) in `/opt/` (or wherever else) by: 35 | ``` 36 | $ cd /opt/ 37 | $ git clone https://github.com/pillone 38 | ``` 39 | > This will produce `/opt/usntssearch/` 40 | 41 | * All the example configuration files are with respect to that directory. 42 | 43 | * Edit, if needed, and copy the nginx conf file: `$ sudo cp /opt/usntssearch/large_server/nginx.conf /etc/nginx/` 44 | 45 | * Edit the 'user' field in the files contained in: `/opt/usntssearch/large_server/supervisor/conf.d/*.conf` 46 | 47 | 48 | * Depending on the expected traffic, change the parameter `-w 15` (number of concurrent workers) in `/opt/usntssearch/large_server/supervisor/conf.d/mega2.py` 49 | 50 | * Copy the supervisor configuration: `$ sudo cp -r /opt/usntssearch/large_server/supervisor /etc` 51 | 52 | * Remove the init.d file `$ sudo rm /etc/init.d/nginx`. Supervisor will take care of running and restarting all the services 53 | 54 | --- 55 | 56 | ### STEP 2: All systems ready! 57 | 58 | * Generate a valid configuration for NZBMegasearch: 59 | ``` 60 | $ cd /opt/usntssearch/NZBmegasearch 61 | $ python mega2.py 62 | ``` 63 | > then visit `http://serveripaddress:5000` and configure it. Alternatively, you can use a `custom_params.ini` that you have already saved from a home install. 64 | 65 | * This will start all the services: 66 | ``` 67 | $ sudo supervisorctl reread 68 | $ sudo supervisorctl update 69 | $ sudo supervisorctl restart all 70 | ``` 71 | 72 | * **THAT'S IT! You have successfully installed NZBMegasearch!** 73 | 74 | ` 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /NZBmegasearch/large_server/supervisor/conf.d/README: -------------------------------------------------------------------------------- 1 | Place custom configuration files for supervisor here. They 2 | will be read after the main configuration file in 3 | /etc/supervisor/supervisord.conf 4 | -------------------------------------------------------------------------------- /NZBmegasearch/large_server/supervisor/conf.d/detachedtrend.conf: -------------------------------------------------------------------------------- 1 | [program:detached] 2 | command = /usr/bin/python detachedtrend.py 3 | directory = /opt/usntssearch/NZBmegasearch/ 4 | user = zerobyte 5 | autostart = true 6 | autorestart = true 7 | -------------------------------------------------------------------------------- /NZBmegasearch/large_server/supervisor/conf.d/mega.conf: -------------------------------------------------------------------------------- 1 | [program:mega] 2 | command = /usr/local/bin/gunicorn mega2:app --bind unix:/tmp/gunicorn.sock -w 15 3 | directory = /opt/usntssearch/NZBmegasearch/ 4 | user = zerobyte 5 | autostart = true 6 | autorestart = true 7 | -------------------------------------------------------------------------------- /NZBmegasearch/large_server/supervisor/conf.d/nginx.conf: -------------------------------------------------------------------------------- 1 | [program:nginx] 2 | command=/usr/sbin/nginx 3 | user = root 4 | autostart = true 5 | autorestart = true 6 | -------------------------------------------------------------------------------- /NZBmegasearch/large_server/supervisor/supervisord.conf: -------------------------------------------------------------------------------- 1 | ; supervisor config file 2 | 3 | [unix_http_server] 4 | file=/var/run//supervisor.sock ; (the path to the socket file) 5 | chmod=0700 ; sockef file mode (default 0700) 6 | 7 | [supervisord] 8 | logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log) 9 | pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid) 10 | childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP) 11 | 12 | ; the below section must remain in the config file for RPC 13 | ; (supervisorctl/web interface) to work, additional interfaces may be 14 | ; added by defining them in separate rpcinterface: sections 15 | [rpcinterface:supervisor] 16 | supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface 17 | 18 | [supervisorctl] 19 | serverurl=unix:///var/run//supervisor.sock ; use a unix:// URL for a unix socket 20 | 21 | ; The [include] section can just contain the "files" setting. This 22 | ; setting can list multiple files (separated by whitespace or 23 | ; newlines). It can also contain wildcards. The filenames are 24 | ; interpreted as relative to this file. Included files *cannot* 25 | ; include files themselves. 26 | 27 | [include] 28 | files = /etc/supervisor/conf.d/*.conf 29 | -------------------------------------------------------------------------------- /NZBmegasearch/logs/placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/logs/placeholder -------------------------------------------------------------------------------- /NZBmegasearch/mechanize/_auth.py: -------------------------------------------------------------------------------- 1 | """HTTP Authentication and Proxy support. 2 | 3 | 4 | Copyright 2006 John J. Lee 5 | 6 | This code is free software; you can redistribute it and/or modify it under 7 | the terms of the BSD or ZPL 2.1 licenses (see the file COPYING.txt 8 | included with the distribution). 9 | 10 | """ 11 | 12 | from _urllib2_fork import HTTPPasswordMgr 13 | 14 | 15 | # TODO: stop deriving from HTTPPasswordMgr 16 | class HTTPProxyPasswordMgr(HTTPPasswordMgr): 17 | # has default realm and host/port 18 | def add_password(self, realm, uri, user, passwd): 19 | # uri could be a single URI or a sequence 20 | if uri is None or isinstance(uri, basestring): 21 | uris = [uri] 22 | else: 23 | uris = uri 24 | passwd_by_domain = self.passwd.setdefault(realm, {}) 25 | for uri in uris: 26 | for default_port in True, False: 27 | reduced_uri = self.reduce_uri(uri, default_port) 28 | passwd_by_domain[reduced_uri] = (user, passwd) 29 | 30 | def find_user_password(self, realm, authuri): 31 | attempts = [(realm, authuri), (None, authuri)] 32 | # bleh, want default realm to take precedence over default 33 | # URI/authority, hence this outer loop 34 | for default_uri in False, True: 35 | for realm, authuri in attempts: 36 | authinfo_by_domain = self.passwd.get(realm, {}) 37 | for default_port in True, False: 38 | reduced_authuri = self.reduce_uri(authuri, default_port) 39 | for uri, authinfo in authinfo_by_domain.iteritems(): 40 | if uri is None and not default_uri: 41 | continue 42 | if self.is_suburi(uri, reduced_authuri): 43 | return authinfo 44 | user, password = None, None 45 | 46 | if user is not None: 47 | break 48 | return user, password 49 | 50 | def reduce_uri(self, uri, default_port=True): 51 | if uri is None: 52 | return None 53 | return HTTPPasswordMgr.reduce_uri(self, uri, default_port) 54 | 55 | def is_suburi(self, base, test): 56 | if base is None: 57 | # default to the proxy's host/port 58 | hostport, path = test 59 | base = (hostport, "/") 60 | return HTTPPasswordMgr.is_suburi(self, base, test) 61 | 62 | 63 | class HTTPSClientCertMgr(HTTPPasswordMgr): 64 | # implementation inheritance: this is not a proper subclass 65 | def add_key_cert(self, uri, key_file, cert_file): 66 | self.add_password(None, uri, key_file, cert_file) 67 | 68 | def find_key_cert(self, authuri): 69 | return HTTPPasswordMgr.find_user_password(self, None, authuri) 70 | -------------------------------------------------------------------------------- /NZBmegasearch/mechanize/_debug.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | from _response import response_seek_wrapper 4 | from _urllib2_fork import BaseHandler 5 | 6 | 7 | class HTTPResponseDebugProcessor(BaseHandler): 8 | handler_order = 900 # before redirections, after everything else 9 | 10 | def http_response(self, request, response): 11 | if not hasattr(response, "seek"): 12 | response = response_seek_wrapper(response) 13 | info = logging.getLogger("mechanize.http_responses").info 14 | try: 15 | info(response.read()) 16 | finally: 17 | response.seek(0) 18 | info("*****************************************************") 19 | return response 20 | 21 | https_response = http_response 22 | 23 | 24 | class HTTPRedirectDebugProcessor(BaseHandler): 25 | def http_request(self, request): 26 | if hasattr(request, "redirect_dict"): 27 | info = logging.getLogger("mechanize.http_redirects").info 28 | info("redirecting to %s", request.get_full_url()) 29 | return request 30 | -------------------------------------------------------------------------------- /NZBmegasearch/mechanize/_gzip.py: -------------------------------------------------------------------------------- 1 | from cStringIO import StringIO 2 | 3 | import _response 4 | import _urllib2_fork 5 | 6 | 7 | # GzipConsumer was taken from Fredrik Lundh's effbot.org-0.1-20041009 library 8 | class GzipConsumer: 9 | def __init__(self, consumer): 10 | self.__consumer = consumer 11 | self.__decoder = None 12 | self.__data = "" 13 | 14 | def __getattr__(self, key): 15 | return getattr(self.__consumer, key) 16 | 17 | def feed(self, data): 18 | if self.__decoder is None: 19 | # check if we have a full gzip header 20 | data = self.__data + data 21 | try: 22 | i = 10 23 | flag = ord(data[3]) 24 | if flag & 4: # extra 25 | x = ord(data[i]) + 256 * ord(data[i + 1]) 26 | i = i + 2 + x 27 | if flag & 8: # filename 28 | while ord(data[i]): 29 | i = i + 1 30 | i = i + 1 31 | if flag & 16: # comment 32 | while ord(data[i]): 33 | i = i + 1 34 | i = i + 1 35 | if flag & 2: # crc 36 | i = i + 2 37 | if len(data) < i: 38 | raise IndexError("not enough data") 39 | if data[:3] != "\x1f\x8b\x08": 40 | raise IOError("invalid gzip data") 41 | data = data[i:] 42 | except IndexError: 43 | self.__data = data 44 | return # need more data 45 | import zlib 46 | 47 | self.__data = "" 48 | self.__decoder = zlib.decompressobj(-zlib.MAX_WBITS) 49 | data = self.__decoder.decompress(data) 50 | if data: 51 | self.__consumer.feed(data) 52 | 53 | def close(self): 54 | if self.__decoder: 55 | data = self.__decoder.flush() 56 | if data: 57 | self.__consumer.feed(data) 58 | self.__consumer.close() 59 | 60 | 61 | # -------------------------------------------------------------------- 62 | 63 | # the rest of this module is John Lee's stupid code, not 64 | # Fredrik's nice code :-) 65 | 66 | class stupid_gzip_consumer: 67 | def __init__(self): self.data = [] 68 | 69 | def feed(self, data): self.data.append(data) 70 | 71 | 72 | class stupid_gzip_wrapper(_response.closeable_response): 73 | def __init__(self, response): 74 | self._response = response 75 | 76 | c = stupid_gzip_consumer() 77 | gzc = GzipConsumer(c) 78 | gzc.feed(response.read()) 79 | self.__data = StringIO("".join(c.data)) 80 | 81 | def read(self, size=-1): 82 | return self.__data.read(size) 83 | 84 | def readline(self, size=-1): 85 | return self.__data.readline(size) 86 | 87 | def readlines(self, sizehint=-1): 88 | return self.__data.readlines(sizehint) 89 | 90 | def __getattr__(self, name): 91 | # delegate unknown methods/attributes 92 | return getattr(self._response, name) 93 | 94 | 95 | class HTTPGzipProcessor(_urllib2_fork.BaseHandler): 96 | handler_order = 200 # response processing before HTTPEquivProcessor 97 | 98 | def http_request(self, request): 99 | request.add_header("Accept-Encoding", "gzip") 100 | return request 101 | 102 | def http_response(self, request, response): 103 | # post-process response 104 | enc_hdrs = response.info().getheaders("Content-encoding") 105 | for enc_hdr in enc_hdrs: 106 | if ("gzip" in enc_hdr) or ("compress" in enc_hdr): 107 | return stupid_gzip_wrapper(response) 108 | return response 109 | 110 | https_response = http_response 111 | -------------------------------------------------------------------------------- /NZBmegasearch/mechanize/_request.py: -------------------------------------------------------------------------------- 1 | """Integration with Python standard library module urllib2: Request class. 2 | 3 | Copyright 2004-2006 John J Lee 4 | 5 | This code is free software; you can redistribute it and/or modify it 6 | under the terms of the BSD or ZPL 2.1 licenses (see the file 7 | COPYING.txt included with the distribution). 8 | 9 | """ 10 | 11 | import logging 12 | 13 | import _rfc3986 14 | import _sockettimeout 15 | import _urllib2_fork 16 | 17 | warn = logging.getLogger("mechanize").warning 18 | 19 | 20 | class Request(_urllib2_fork.Request): 21 | def __init__(self, url, data=None, headers={}, 22 | origin_req_host=None, unverifiable=False, visit=None, 23 | timeout=_sockettimeout._GLOBAL_DEFAULT_TIMEOUT): 24 | # In mechanize 0.2, the interpretation of a unicode url argument will 25 | # change: A unicode url argument will be interpreted as an IRI, and a 26 | # bytestring as a URI. For now, we accept unicode or bytestring. We 27 | # don't insist that the value is always a URI (specifically, must only 28 | # contain characters which are legal), because that might break working 29 | # code (who knows what bytes some servers want to see, especially with 30 | # browser plugins for internationalised URIs). 31 | if not _rfc3986.is_clean_uri(url): 32 | warn("url argument is not a URI " 33 | "(contains illegal characters) %r" % url) 34 | _urllib2_fork.Request.__init__(self, url, data, headers) 35 | self.selector = None 36 | self.visit = visit 37 | self.timeout = timeout 38 | 39 | def __str__(self): 40 | return "" % self.get_full_url() 41 | -------------------------------------------------------------------------------- /NZBmegasearch/mechanize/_sockettimeout.py: -------------------------------------------------------------------------------- 1 | import socket 2 | 3 | try: 4 | _GLOBAL_DEFAULT_TIMEOUT = socket._GLOBAL_DEFAULT_TIMEOUT 5 | except AttributeError: 6 | _GLOBAL_DEFAULT_TIMEOUT = object() 7 | -------------------------------------------------------------------------------- /NZBmegasearch/mechanize/_urllib2.py: -------------------------------------------------------------------------------- 1 | # urllib2 work-alike interface 2 | # ...from urllib2... 3 | from urllib2 import \ 4 | URLError, \ 5 | HTTPError 6 | # ...and from mechanize 7 | from _auth import \ 8 | HTTPProxyPasswordMgr, \ 9 | HTTPSClientCertMgr 10 | from _debug import \ 11 | HTTPResponseDebugProcessor, \ 12 | HTTPRedirectDebugProcessor 13 | # crap ATM 14 | ## from _gzip import \ 15 | ## HTTPGzipProcessor 16 | from _urllib2_fork import \ 17 | AbstractBasicAuthHandler, \ 18 | AbstractDigestAuthHandler, \ 19 | BaseHandler, \ 20 | CacheFTPHandler, \ 21 | FileHandler, \ 22 | FTPHandler, \ 23 | HTTPBasicAuthHandler, \ 24 | HTTPCookieProcessor, \ 25 | HTTPDefaultErrorHandler, \ 26 | HTTPDigestAuthHandler, \ 27 | HTTPErrorProcessor, \ 28 | HTTPHandler, \ 29 | HTTPPasswordMgr, \ 30 | HTTPPasswordMgrWithDefaultRealm, \ 31 | HTTPRedirectHandler, \ 32 | ProxyBasicAuthHandler, \ 33 | ProxyDigestAuthHandler, \ 34 | ProxyHandler, \ 35 | UnknownHandler 36 | from _http import \ 37 | HTTPEquivProcessor, \ 38 | HTTPRefererProcessor, \ 39 | HTTPRefreshProcessor, \ 40 | HTTPRobotRulesProcessor, \ 41 | RobotExclusionError 42 | import httplib 43 | 44 | if hasattr(httplib, 'HTTPS'): 45 | from _urllib2_fork import HTTPSHandler 46 | del httplib 47 | from _opener import OpenerDirector, \ 48 | SeekableResponseOpener, \ 49 | build_opener, install_opener, urlopen 50 | from _request import \ 51 | Request 52 | -------------------------------------------------------------------------------- /NZBmegasearch/mechanize/_version.py: -------------------------------------------------------------------------------- 1 | "0.2.5" 2 | __version__ = (0, 2, 5, None, None) 3 | -------------------------------------------------------------------------------- /NZBmegasearch/openshift/app.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import imp 3 | import os 4 | import sys 5 | 6 | PYCART_DIR = ''.join(['python-', '.'.join(map(str, sys.version_info[:2]))]) 7 | 8 | try: 9 | zvirtenv = os.path.join(os.environ['OPENSHIFT_HOMEDIR'], PYCART_DIR, 10 | 'virtenv', 'bin', 'activate_this.py') 11 | execfile(zvirtenv, dict(__file__=zvirtenv)) 12 | except IOError: 13 | pass 14 | 15 | 16 | def run_gevent_server(app, ip, port=8080): 17 | from gevent.pywsgi import WSGIServer 18 | 19 | WSGIServer((ip, port), app).serve_forever() 20 | 21 | 22 | def run_simple_httpd_server(app, ip, port=8080): 23 | from wsgiref.simple_server import make_server 24 | 25 | make_server(ip, port, app).serve_forever() 26 | 27 | # 28 | # IMPORTANT: Put any additional includes below this line. If placed above this 29 | # line, it's possible required libraries won't be in your searchable path 30 | # 31 | 32 | 33 | # 34 | # main(): 35 | # 36 | if __name__ == '__main__': 37 | ip = os.environ['OPENSHIFT_PYTHON_IP'] 38 | port = int(os.environ['OPENSHIFT_PYTHON_PORT']) 39 | 40 | zapp = imp.load_source('application', 'wsgi/usntssearch/NZBmegasearch/application') 41 | 42 | # Use gevent if we have it, otherwise run a simple httpd server. 43 | print 'Starting WSGIServer on %s:%d ... ' % (ip, port) 44 | try: 45 | run_gevent_server(zapp.application, ip, port) 46 | except: 47 | print 'gevent probably not installed - using default simple server ...' 48 | run_simple_httpd_server(zapp.application, ip, port) 49 | -------------------------------------------------------------------------------- /NZBmegasearch/openshift/application: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import os 3 | import sys 4 | 5 | sys.path.insert(0, os.path.dirname(__file__) or '.') 6 | PY_VERSION = 'python-' + ('.'.join(map(str, sys.version_info[:2]))) 7 | PY_DIR = os.environ['HOME'] + '/' + PY_VERSION 8 | 9 | virtenv = PY_DIR + '/virtenv/' 10 | 11 | PY_CACHE = virtenv + 'lib/' + PY_VERSION + '/site-packages' 12 | 13 | os.environ['PYTHON_EGG_CACHE'] = os.path.join(PY_CACHE) 14 | virtualenv = os.path.join(virtenv, 'bin/activate_this.py') 15 | 16 | try: 17 | execfile(virtualenv, dict(__file__=virtualenv)) 18 | except IOError: 19 | pass 20 | 21 | # ~ this is for exclusive usage of Openshift 22 | from mega2 import app as application 23 | -------------------------------------------------------------------------------- /NZBmegasearch/openshift/install_openshift.sh: -------------------------------------------------------------------------------- 1 | #~ OPENSHIFT_DATA_DIR 2 | echo '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*' 3 | echo ' NZBMEGASEARCH install for Openshift' 4 | echo '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*' 5 | 6 | echo 'Running update -- 01/02' 7 | git fetch 8 | 9 | echo 'Running update -- 02/02' 10 | git reset --hard origin/master 11 | 12 | echo 'Preparing...' 13 | cp ../builtin_params.ini . 14 | 15 | #~ SETS DEFAULT PWD 16 | grep -v '^general_user' ../builtin_params.ini | grep -v '^general_pwd' > tmpfl.tmp 17 | printf 'general_user = NZBMadmin\ngeneral_pwd = NZBMadmin\n' >> ../builtin_params.ini 18 | 19 | cp ../builtin_params.ini $OPENSHIFT_DATA_DIR 20 | cp ../vernum.num $OPENSHIFT_DATA_DIR 21 | cp application $OPENSHIFT_REPO_DIR/wsgi/usntssearch/NZBmegasearch/ 22 | cp app.py $OPENSHIFT_REPO_DIR/ 23 | 24 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # __ 4 | # /__) _ _ _ _ _/ _ 5 | # / ( (- (/ (/ (- _) / _) 6 | # / 7 | 8 | """ 9 | requests HTTP library 10 | ~~~~~~~~~~~~~~~~~~~~~ 11 | 12 | Requests is an HTTP library, written in Python, for human beings. Basic GET 13 | usage: 14 | 15 | >>> import requests 16 | >>> r = requests.get('http://python.org') 17 | >>> r.status_code 18 | 200 19 | >>> 'Python is a programming language' in r.content 20 | True 21 | 22 | ... or POST: 23 | 24 | >>> payload = dict(key1='value1', key2='value2') 25 | >>> r = requests.post("http://httpbin.org/post", data=payload) 26 | >>> print r.text 27 | { 28 | ... 29 | "form": { 30 | "key2": "value2", 31 | "key1": "value1" 32 | }, 33 | ... 34 | } 35 | 36 | The other HTTP methods are supported - see `requests.api`. Full documentation 37 | is at . 38 | 39 | :copyright: (c) 2013 by Kenneth Reitz. 40 | :license: Apache 2.0, see LICENSE for more details. 41 | 42 | """ 43 | 44 | __title__ = 'requests' 45 | __version__ = '1.1.0' 46 | __build__ = 0x010100 47 | __author__ = 'Kenneth Reitz' 48 | __license__ = 'Apache 2.0' 49 | __copyright__ = 'Copyright 2013 Kenneth Reitz' 50 | 51 | from . import utils 52 | from .models import Request, Response, PreparedRequest 53 | from .api import request, get, head, post, patch, put, delete, options 54 | from .sessions import session, Session 55 | from .status_codes import codes 56 | from .exceptions import ( 57 | RequestException, Timeout, URLRequired, 58 | TooManyRedirects, HTTPError, ConnectionError 59 | ) 60 | 61 | # Set default logging handler to avoid "No handler found" warnings. 62 | import logging 63 | 64 | try: # Python 2.7+ 65 | from logging import NullHandler 66 | except ImportError: 67 | class NullHandler(logging.Handler): 68 | def emit(self, record): 69 | pass 70 | 71 | logging.getLogger(__name__).addHandler(NullHandler()) 72 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/certs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | certs.py 6 | ~~~~~~~~ 7 | 8 | This module returns the preferred default CA certificate bundle. 9 | 10 | If you are packaging Requests, e.g., for a Linux distribution or a managed 11 | environment, you can change the definition of where() to return a separately 12 | packaged CA bundle. 13 | """ 14 | 15 | import os.path 16 | 17 | 18 | def where(): 19 | """Return the preferred certificate bundle.""" 20 | # vendored bundle inside Requests 21 | return os.path.join(os.path.dirname(__file__), 'cacert.pem') 22 | 23 | 24 | if __name__ == '__main__': 25 | print(where()) 26 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/compat.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | pythoncompat 5 | """ 6 | 7 | from .packages import charade as chardet 8 | 9 | import sys 10 | 11 | # ------- 12 | # Pythons 13 | # ------- 14 | 15 | # Syntax sugar. 16 | _ver = sys.version_info 17 | 18 | #: Python 2.x? 19 | is_py2 = (_ver[0] == 2) 20 | 21 | #: Python 3.x? 22 | is_py3 = (_ver[0] == 3) 23 | 24 | #: Python 3.0.x 25 | is_py30 = (is_py3 and _ver[1] == 0) 26 | 27 | #: Python 3.1.x 28 | is_py31 = (is_py3 and _ver[1] == 1) 29 | 30 | #: Python 3.2.x 31 | is_py32 = (is_py3 and _ver[1] == 2) 32 | 33 | #: Python 3.3.x 34 | is_py33 = (is_py3 and _ver[1] == 3) 35 | 36 | #: Python 3.4.x 37 | is_py34 = (is_py3 and _ver[1] == 4) 38 | 39 | #: Python 2.7.x 40 | is_py27 = (is_py2 and _ver[1] == 7) 41 | 42 | #: Python 2.6.x 43 | is_py26 = (is_py2 and _ver[1] == 6) 44 | 45 | #: Python 2.5.x 46 | is_py25 = (is_py2 and _ver[1] == 5) 47 | 48 | #: Python 2.4.x 49 | is_py24 = (is_py2 and _ver[1] == 4) # I'm assuming this is not by choice. 50 | 51 | 52 | # --------- 53 | # Platforms 54 | # --------- 55 | 56 | 57 | # Syntax sugar. 58 | _ver = sys.version.lower() 59 | 60 | is_pypy = ('pypy' in _ver) 61 | is_jython = ('jython' in _ver) 62 | is_ironpython = ('iron' in _ver) 63 | 64 | # Assume CPython, if nothing else. 65 | is_cpython = not any((is_pypy, is_jython, is_ironpython)) 66 | 67 | # Windows-based system. 68 | is_windows = 'win32' in str(sys.platform).lower() 69 | 70 | # Standard Linux 2+ system. 71 | is_linux = ('linux' in str(sys.platform).lower()) 72 | is_osx = ('darwin' in str(sys.platform).lower()) 73 | is_hpux = ('hpux' in str(sys.platform).lower()) # Complete guess. 74 | is_solaris = ('solar==' in str(sys.platform).lower()) # Complete guess. 75 | 76 | try: 77 | import simplejson as json 78 | except ImportError: 79 | import json 80 | 81 | # --------- 82 | # Specifics 83 | # --------- 84 | 85 | if is_py2: 86 | from urllib import quote, unquote, quote_plus, unquote_plus, urlencode 87 | from urlparse import urlparse, urlunparse, urljoin, urlsplit, urldefrag 88 | from urllib2 import parse_http_list 89 | import cookielib 90 | from Cookie import Morsel 91 | from StringIO import StringIO 92 | from .packages.urllib3.packages.ordered_dict import OrderedDict 93 | 94 | builtin_str = str 95 | bytes = str 96 | str = unicode 97 | basestring = basestring 98 | numeric_types = (int, long, float) 99 | 100 | 101 | elif is_py3: 102 | from urllib.parse import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, quote_plus, \ 103 | unquote_plus, urldefrag 104 | from urllib.request import parse_http_list 105 | from http import cookiejar as cookielib 106 | from http.cookies import Morsel 107 | from io import StringIO 108 | from collections import OrderedDict 109 | 110 | builtin_str = str 111 | str = str 112 | bytes = bytes 113 | basestring = (str, bytes) 114 | numeric_types = (int, float) 115 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/exceptions.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | requests.exceptions 5 | ~~~~~~~~~~~~~~~~~~~ 6 | 7 | This module contains the set of Requests' exceptions. 8 | 9 | """ 10 | 11 | 12 | class RequestException(RuntimeError): 13 | """There was an ambiguous exception that occurred while handling your 14 | request.""" 15 | 16 | 17 | class HTTPError(RequestException): 18 | """An HTTP error occurred.""" 19 | response = None 20 | 21 | 22 | class ConnectionError(RequestException): 23 | """A Connection error occurred.""" 24 | 25 | 26 | class SSLError(ConnectionError): 27 | """An SSL error occurred.""" 28 | 29 | 30 | class Timeout(RequestException): 31 | """The request timed out.""" 32 | 33 | 34 | class URLRequired(RequestException): 35 | """A valid URL is required to make a request.""" 36 | 37 | 38 | class TooManyRedirects(RequestException): 39 | """Too many redirects.""" 40 | 41 | 42 | class MissingSchema(RequestException, ValueError): 43 | """The URL schema (e.g. http or https) is missing.""" 44 | 45 | 46 | class InvalidSchema(RequestException, ValueError): 47 | """See defaults.py for valid schemas.""" 48 | 49 | 50 | class InvalidURL(RequestException, ValueError): 51 | """ The URL provided was somehow invalid. """ 52 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/hooks.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | requests.hooks 5 | ~~~~~~~~~~~~~~ 6 | 7 | This module provides the capabilities for the Requests hooks system. 8 | 9 | Available hooks: 10 | 11 | ``response``: 12 | The response generated from a Request. 13 | 14 | """ 15 | 16 | HOOKS = ['response'] 17 | 18 | 19 | def default_hooks(): 20 | hooks = {} 21 | for event in HOOKS: 22 | hooks[event] = [] 23 | return hooks 24 | 25 | 26 | # TODO: response is the only one 27 | 28 | 29 | def dispatch_hook(key, hooks, hook_data): 30 | """Dispatches a hook dictionary on a given piece of data.""" 31 | 32 | hooks = hooks or dict() 33 | 34 | if key in hooks: 35 | hooks = hooks.get(key) 36 | 37 | if hasattr(hooks, '__call__'): 38 | hooks = [hooks] 39 | 40 | for hook in hooks: 41 | _hook_data = hook(hook_data) 42 | if _hook_data is not None: 43 | hook_data = _hook_data 44 | 45 | return hook_data 46 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | 3 | from . import urllib3 4 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/charade/__init__.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # This library is free software; you can redistribute it and/or 3 | # modify it under the terms of the GNU Lesser General Public 4 | # License as published by the Free Software Foundation; either 5 | # version 2.1 of the License, or (at your option) any later version. 6 | # 7 | # This library is distributed in the hope that it will be useful, 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | # Lesser General Public License for more details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public 13 | # License along with this library; if not, write to the Free Software 14 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 15 | # 02110-1301 USA 16 | ######################### END LICENSE BLOCK ######################### 17 | 18 | __version__ = "1.0.1" 19 | 20 | 21 | def detect(aBuf): 22 | from . import universaldetector 23 | 24 | u = universaldetector.UniversalDetector() 25 | u.reset() 26 | u.feed(aBuf) 27 | u.close() 28 | return u.result 29 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/charade/big5prober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is Mozilla Communicator client code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | from .mbcharsetprober import MultiByteCharSetProber 29 | from .codingstatemachine import CodingStateMachine 30 | from .chardistribution import Big5DistributionAnalysis 31 | from .mbcssm import Big5SMModel 32 | 33 | 34 | class Big5Prober(MultiByteCharSetProber): 35 | def __init__(self): 36 | MultiByteCharSetProber.__init__(self) 37 | self._mCodingSM = CodingStateMachine(Big5SMModel) 38 | self._mDistributionAnalyzer = Big5DistributionAnalysis() 39 | self.reset() 40 | 41 | def get_charset_name(self): 42 | return "Big5" 43 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/charade/charsetprober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is Mozilla Universal charset detector code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 2001 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # Shy Shalom - original C code 12 | # 13 | # This library is free software; you can redistribute it and/or 14 | # modify it under the terms of the GNU Lesser General Public 15 | # License as published by the Free Software Foundation; either 16 | # version 2.1 of the License, or (at your option) any later version. 17 | # 18 | # This library is distributed in the hope that it will be useful, 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | # Lesser General Public License for more details. 22 | # 23 | # You should have received a copy of the GNU Lesser General Public 24 | # License along with this library; if not, write to the Free Software 25 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 26 | # 02110-1301 USA 27 | ######################### END LICENSE BLOCK ######################### 28 | 29 | from . import constants 30 | import re 31 | 32 | 33 | class CharSetProber: 34 | def __init__(self): 35 | pass 36 | 37 | def reset(self): 38 | self._mState = constants.eDetecting 39 | 40 | def get_charset_name(self): 41 | return None 42 | 43 | def feed(self, aBuf): 44 | pass 45 | 46 | def get_state(self): 47 | return self._mState 48 | 49 | def get_confidence(self): 50 | return 0.0 51 | 52 | def filter_high_bit_only(self, aBuf): 53 | aBuf = re.sub(b'([\x00-\x7F])+', b' ', aBuf) 54 | return aBuf 55 | 56 | def filter_without_english_letters(self, aBuf): 57 | aBuf = re.sub(b'([A-Za-z])+', b' ', aBuf) 58 | return aBuf 59 | 60 | def filter_with_english_letters(self, aBuf): 61 | # TODO 62 | return aBuf 63 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/charade/codingstatemachine.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is mozilla.org code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | from .constants import eStart 29 | from .compat import wrap_ord 30 | 31 | 32 | class CodingStateMachine: 33 | def __init__(self, sm): 34 | self._mModel = sm 35 | self._mCurrentBytePos = 0 36 | self._mCurrentCharLen = 0 37 | self.reset() 38 | 39 | def reset(self): 40 | self._mCurrentState = eStart 41 | 42 | def next_state(self, c): 43 | # for each byte we get its class 44 | # if it is first byte, we also get byte length 45 | # PY3K: aBuf is a byte stream, so c is an int, not a byte 46 | byteCls = self._mModel['classTable'][wrap_ord(c)] 47 | if self._mCurrentState == eStart: 48 | self._mCurrentBytePos = 0 49 | self._mCurrentCharLen = self._mModel['charLenTable'][byteCls] 50 | # from byte's class and stateTable, we get its next state 51 | curr_state = (self._mCurrentState * self._mModel['classFactor'] 52 | + byteCls) 53 | self._mCurrentState = self._mModel['stateTable'][curr_state] 54 | self._mCurrentBytePos += 1 55 | return self._mCurrentState 56 | 57 | def get_current_charlen(self): 58 | return self._mCurrentCharLen 59 | 60 | def get_coding_state_machine(self): 61 | return self._mModel['name'] 62 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/charade/compat.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # Contributor(s): 3 | # Ian Cordasco - port to Python 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2.1 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 18 | # 02110-1301 USA 19 | ######################### END LICENSE BLOCK ######################### 20 | 21 | 22 | def wrap_ord(a): 23 | if isinstance(a, str): 24 | return ord(a) 25 | elif isinstance(a, int): 26 | return a 27 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/charade/constants.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is Mozilla Universal charset detector code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 2001 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # Shy Shalom - original C code 12 | # 13 | # This library is free software; you can redistribute it and/or 14 | # modify it under the terms of the GNU Lesser General Public 15 | # License as published by the Free Software Foundation; either 16 | # version 2.1 of the License, or (at your option) any later version. 17 | # 18 | # This library is distributed in the hope that it will be useful, 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | # Lesser General Public License for more details. 22 | # 23 | # You should have received a copy of the GNU Lesser General Public 24 | # License along with this library; if not, write to the Free Software 25 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 26 | # 02110-1301 USA 27 | ######################### END LICENSE BLOCK ######################### 28 | 29 | _debug = 0 30 | 31 | eDetecting = 0 32 | eFoundIt = 1 33 | eNotMe = 2 34 | 35 | eStart = 0 36 | eError = 1 37 | eItsMe = 2 38 | 39 | SHORTCUT_THRESHOLD = 0.95 40 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/charade/escprober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is mozilla.org code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | from . import constants 29 | from .escsm import (HZSMModel, ISO2022CNSMModel, ISO2022JPSMModel, 30 | ISO2022KRSMModel) 31 | from .charsetprober import CharSetProber 32 | from .codingstatemachine import CodingStateMachine 33 | from .compat import wrap_ord 34 | 35 | 36 | class EscCharSetProber(CharSetProber): 37 | def __init__(self): 38 | CharSetProber.__init__(self) 39 | self._mCodingSM = [ 40 | CodingStateMachine(HZSMModel), 41 | CodingStateMachine(ISO2022CNSMModel), 42 | CodingStateMachine(ISO2022JPSMModel), 43 | CodingStateMachine(ISO2022KRSMModel) 44 | ] 45 | self.reset() 46 | 47 | def reset(self): 48 | CharSetProber.reset(self) 49 | for codingSM in self._mCodingSM: 50 | if not codingSM: 51 | continue 52 | codingSM.active = True 53 | codingSM.reset() 54 | self._mActiveSM = len(self._mCodingSM) 55 | self._mDetectedCharset = None 56 | 57 | def get_charset_name(self): 58 | return self._mDetectedCharset 59 | 60 | def get_confidence(self): 61 | if self._mDetectedCharset: 62 | return 0.99 63 | else: 64 | return 0.00 65 | 66 | def feed(self, aBuf): 67 | for c in aBuf: 68 | # PY3K: aBuf is a byte array, so c is an int, not a byte 69 | for codingSM in self._mCodingSM: 70 | if not codingSM: 71 | continue 72 | if not codingSM.active: 73 | continue 74 | codingState = codingSM.next_state(wrap_ord(c)) 75 | if codingState == constants.eError: 76 | codingSM.active = False 77 | self._mActiveSM -= 1 78 | if self._mActiveSM <= 0: 79 | self._mState = constants.eNotMe 80 | return self.get_state() 81 | elif codingState == constants.eItsMe: 82 | self._mState = constants.eFoundIt 83 | self._mDetectedCharset = codingSM.get_coding_state_machine() # nopep8 84 | return self.get_state() 85 | 86 | return self.get_state() 87 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/charade/eucjpprober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is mozilla.org code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | import sys 29 | from . import constants 30 | from .mbcharsetprober import MultiByteCharSetProber 31 | from .codingstatemachine import CodingStateMachine 32 | from .chardistribution import EUCJPDistributionAnalysis 33 | from .jpcntx import EUCJPContextAnalysis 34 | from .mbcssm import EUCJPSMModel 35 | 36 | 37 | class EUCJPProber(MultiByteCharSetProber): 38 | def __init__(self): 39 | MultiByteCharSetProber.__init__(self) 40 | self._mCodingSM = CodingStateMachine(EUCJPSMModel) 41 | self._mDistributionAnalyzer = EUCJPDistributionAnalysis() 42 | self._mContextAnalyzer = EUCJPContextAnalysis() 43 | self.reset() 44 | 45 | def reset(self): 46 | MultiByteCharSetProber.reset(self) 47 | self._mContextAnalyzer.reset() 48 | 49 | def get_charset_name(self): 50 | return "EUC-JP" 51 | 52 | def feed(self, aBuf): 53 | aLen = len(aBuf) 54 | for i in range(0, aLen): 55 | # PY3K: aBuf is a byte array, so aBuf[i] is an int, not a byte 56 | codingState = self._mCodingSM.next_state(aBuf[i]) 57 | if codingState == constants.eError: 58 | if constants._debug: 59 | sys.stderr.write(self.get_charset_name() 60 | + ' prober hit error at byte ' + str(i) 61 | + '\n') 62 | self._mState = constants.eNotMe 63 | break 64 | elif codingState == constants.eItsMe: 65 | self._mState = constants.eFoundIt 66 | break 67 | elif codingState == constants.eStart: 68 | charLen = self._mCodingSM.get_current_charlen() 69 | if i == 0: 70 | self._mLastChar[1] = aBuf[0] 71 | self._mContextAnalyzer.feed(self._mLastChar, charLen) 72 | self._mDistributionAnalyzer.feed(self._mLastChar, charLen) 73 | else: 74 | self._mContextAnalyzer.feed(aBuf[i - 1:i + 1], charLen) 75 | self._mDistributionAnalyzer.feed(aBuf[i - 1:i + 1], 76 | charLen) 77 | 78 | self._mLastChar[0] = aBuf[aLen - 1] 79 | 80 | if self.get_state() == constants.eDetecting: 81 | if (self._mContextAnalyzer.got_enough_data() and 82 | (self.get_confidence() > constants.SHORTCUT_THRESHOLD)): 83 | self._mState = constants.eFoundIt 84 | 85 | return self.get_state() 86 | 87 | def get_confidence(self): 88 | contxtCf = self._mContextAnalyzer.get_confidence() 89 | distribCf = self._mDistributionAnalyzer.get_confidence() 90 | return max(contxtCf, distribCf) 91 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/charade/euckrprober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is mozilla.org code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | from .mbcharsetprober import MultiByteCharSetProber 29 | from .codingstatemachine import CodingStateMachine 30 | from .chardistribution import EUCKRDistributionAnalysis 31 | from .mbcssm import EUCKRSMModel 32 | 33 | 34 | class EUCKRProber(MultiByteCharSetProber): 35 | def __init__(self): 36 | MultiByteCharSetProber.__init__(self) 37 | self._mCodingSM = CodingStateMachine(EUCKRSMModel) 38 | self._mDistributionAnalyzer = EUCKRDistributionAnalysis() 39 | self.reset() 40 | 41 | def get_charset_name(self): 42 | return "EUC-KR" 43 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/charade/euctwprober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is mozilla.org code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | from .mbcharsetprober import MultiByteCharSetProber 29 | from .codingstatemachine import CodingStateMachine 30 | from .chardistribution import EUCTWDistributionAnalysis 31 | from .mbcssm import EUCTWSMModel 32 | 33 | 34 | class EUCTWProber(MultiByteCharSetProber): 35 | def __init__(self): 36 | MultiByteCharSetProber.__init__(self) 37 | self._mCodingSM = CodingStateMachine(EUCTWSMModel) 38 | self._mDistributionAnalyzer = EUCTWDistributionAnalysis() 39 | self.reset() 40 | 41 | def get_charset_name(self): 42 | return "EUC-TW" 43 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/charade/gb2312prober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is mozilla.org code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | from .mbcharsetprober import MultiByteCharSetProber 29 | from .codingstatemachine import CodingStateMachine 30 | from .chardistribution import GB2312DistributionAnalysis 31 | from .mbcssm import GB2312SMModel 32 | 33 | 34 | class GB2312Prober(MultiByteCharSetProber): 35 | def __init__(self): 36 | MultiByteCharSetProber.__init__(self) 37 | self._mCodingSM = CodingStateMachine(GB2312SMModel) 38 | self._mDistributionAnalyzer = GB2312DistributionAnalysis() 39 | self.reset() 40 | 41 | def get_charset_name(self): 42 | return "GB2312" 43 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/charade/mbcharsetprober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is Mozilla Universal charset detector code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 2001 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # Shy Shalom - original C code 12 | # Proofpoint, Inc. 13 | # 14 | # This library is free software; you can redistribute it and/or 15 | # modify it under the terms of the GNU Lesser General Public 16 | # License as published by the Free Software Foundation; either 17 | # version 2.1 of the License, or (at your option) any later version. 18 | # 19 | # This library is distributed in the hope that it will be useful, 20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | # Lesser General Public License for more details. 23 | # 24 | # You should have received a copy of the GNU Lesser General Public 25 | # License along with this library; if not, write to the Free Software 26 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 27 | # 02110-1301 USA 28 | ######################### END LICENSE BLOCK ######################### 29 | 30 | import sys 31 | from . import constants 32 | from .charsetprober import CharSetProber 33 | 34 | 35 | class MultiByteCharSetProber(CharSetProber): 36 | def __init__(self): 37 | CharSetProber.__init__(self) 38 | self._mDistributionAnalyzer = None 39 | self._mCodingSM = None 40 | self._mLastChar = [0, 0] 41 | 42 | def reset(self): 43 | CharSetProber.reset(self) 44 | if self._mCodingSM: 45 | self._mCodingSM.reset() 46 | if self._mDistributionAnalyzer: 47 | self._mDistributionAnalyzer.reset() 48 | self._mLastChar = [0, 0] 49 | 50 | def get_charset_name(self): 51 | pass 52 | 53 | def feed(self, aBuf): 54 | aLen = len(aBuf) 55 | for i in range(0, aLen): 56 | codingState = self._mCodingSM.next_state(aBuf[i]) 57 | if codingState == constants.eError: 58 | if constants._debug: 59 | sys.stderr.write(self.get_charset_name() 60 | + ' prober hit error at byte ' + str(i) 61 | + '\n') 62 | self._mState = constants.eNotMe 63 | break 64 | elif codingState == constants.eItsMe: 65 | self._mState = constants.eFoundIt 66 | break 67 | elif codingState == constants.eStart: 68 | charLen = self._mCodingSM.get_current_charlen() 69 | if i == 0: 70 | self._mLastChar[1] = aBuf[0] 71 | self._mDistributionAnalyzer.feed(self._mLastChar, charLen) 72 | else: 73 | self._mDistributionAnalyzer.feed(aBuf[i - 1:i + 1], 74 | charLen) 75 | 76 | self._mLastChar[0] = aBuf[aLen - 1] 77 | 78 | if self.get_state() == constants.eDetecting: 79 | if (self._mDistributionAnalyzer.got_enough_data() and 80 | (self.get_confidence() > constants.SHORTCUT_THRESHOLD)): 81 | self._mState = constants.eFoundIt 82 | 83 | return self.get_state() 84 | 85 | def get_confidence(self): 86 | return self._mDistributionAnalyzer.get_confidence() 87 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/charade/mbcsgroupprober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is Mozilla Universal charset detector code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 2001 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # Shy Shalom - original C code 12 | # Proofpoint, Inc. 13 | # 14 | # This library is free software; you can redistribute it and/or 15 | # modify it under the terms of the GNU Lesser General Public 16 | # License as published by the Free Software Foundation; either 17 | # version 2.1 of the License, or (at your option) any later version. 18 | # 19 | # This library is distributed in the hope that it will be useful, 20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | # Lesser General Public License for more details. 23 | # 24 | # You should have received a copy of the GNU Lesser General Public 25 | # License along with this library; if not, write to the Free Software 26 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 27 | # 02110-1301 USA 28 | ######################### END LICENSE BLOCK ######################### 29 | 30 | from .charsetgroupprober import CharSetGroupProber 31 | from .utf8prober import UTF8Prober 32 | from .sjisprober import SJISProber 33 | from .eucjpprober import EUCJPProber 34 | from .gb2312prober import GB2312Prober 35 | from .euckrprober import EUCKRProber 36 | from .big5prober import Big5Prober 37 | from .euctwprober import EUCTWProber 38 | 39 | 40 | class MBCSGroupProber(CharSetGroupProber): 41 | def __init__(self): 42 | CharSetGroupProber.__init__(self) 43 | self._mProbers = [ 44 | UTF8Prober(), 45 | SJISProber(), 46 | EUCJPProber(), 47 | GB2312Prober(), 48 | EUCKRProber(), 49 | Big5Prober(), 50 | EUCTWProber() 51 | ] 52 | self.reset() 53 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/charade/sbcsgroupprober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is Mozilla Universal charset detector code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 2001 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # Shy Shalom - original C code 12 | # 13 | # This library is free software; you can redistribute it and/or 14 | # modify it under the terms of the GNU Lesser General Public 15 | # License as published by the Free Software Foundation; either 16 | # version 2.1 of the License, or (at your option) any later version. 17 | # 18 | # This library is distributed in the hope that it will be useful, 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | # Lesser General Public License for more details. 22 | # 23 | # You should have received a copy of the GNU Lesser General Public 24 | # License along with this library; if not, write to the Free Software 25 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 26 | # 02110-1301 USA 27 | ######################### END LICENSE BLOCK ######################### 28 | 29 | from .charsetgroupprober import CharSetGroupProber 30 | from .sbcharsetprober import SingleByteCharSetProber 31 | from .langcyrillicmodel import (Win1251CyrillicModel, Koi8rModel, 32 | Latin5CyrillicModel, MacCyrillicModel, 33 | Ibm866Model, Ibm855Model) 34 | from .langgreekmodel import Latin7GreekModel, Win1253GreekModel 35 | from .langbulgarianmodel import Latin5BulgarianModel, Win1251BulgarianModel 36 | from .langhungarianmodel import Latin2HungarianModel, Win1250HungarianModel 37 | from .langthaimodel import TIS620ThaiModel 38 | from .langhebrewmodel import Win1255HebrewModel 39 | from .hebrewprober import HebrewProber 40 | 41 | 42 | class SBCSGroupProber(CharSetGroupProber): 43 | def __init__(self): 44 | CharSetGroupProber.__init__(self) 45 | self._mProbers = [ 46 | SingleByteCharSetProber(Win1251CyrillicModel), 47 | SingleByteCharSetProber(Koi8rModel), 48 | SingleByteCharSetProber(Latin5CyrillicModel), 49 | SingleByteCharSetProber(MacCyrillicModel), 50 | SingleByteCharSetProber(Ibm866Model), 51 | SingleByteCharSetProber(Ibm855Model), 52 | SingleByteCharSetProber(Latin7GreekModel), 53 | SingleByteCharSetProber(Win1253GreekModel), 54 | SingleByteCharSetProber(Latin5BulgarianModel), 55 | SingleByteCharSetProber(Win1251BulgarianModel), 56 | SingleByteCharSetProber(Latin2HungarianModel), 57 | SingleByteCharSetProber(Win1250HungarianModel), 58 | SingleByteCharSetProber(TIS620ThaiModel), 59 | ] 60 | hebrewProber = HebrewProber() 61 | logicalHebrewProber = SingleByteCharSetProber(Win1255HebrewModel, 62 | False, hebrewProber) 63 | visualHebrewProber = SingleByteCharSetProber(Win1255HebrewModel, True, 64 | hebrewProber) 65 | hebrewProber.set_model_probers(logicalHebrewProber, visualHebrewProber) 66 | self._mProbers.extend([hebrewProber, logicalHebrewProber, 67 | visualHebrewProber]) 68 | 69 | self.reset() 70 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/charade/sjisprober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is mozilla.org code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | import sys 29 | from .mbcharsetprober import MultiByteCharSetProber 30 | from .codingstatemachine import CodingStateMachine 31 | from .chardistribution import SJISDistributionAnalysis 32 | from .jpcntx import SJISContextAnalysis 33 | from .mbcssm import SJISSMModel 34 | from . import constants 35 | 36 | 37 | class SJISProber(MultiByteCharSetProber): 38 | def __init__(self): 39 | MultiByteCharSetProber.__init__(self) 40 | self._mCodingSM = CodingStateMachine(SJISSMModel) 41 | self._mDistributionAnalyzer = SJISDistributionAnalysis() 42 | self._mContextAnalyzer = SJISContextAnalysis() 43 | self.reset() 44 | 45 | def reset(self): 46 | MultiByteCharSetProber.reset(self) 47 | self._mContextAnalyzer.reset() 48 | 49 | def get_charset_name(self): 50 | return "SHIFT_JIS" 51 | 52 | def feed(self, aBuf): 53 | aLen = len(aBuf) 54 | for i in range(0, aLen): 55 | codingState = self._mCodingSM.next_state(aBuf[i]) 56 | if codingState == constants.eError: 57 | if constants._debug: 58 | sys.stderr.write(self.get_charset_name() 59 | + ' prober hit error at byte ' + str(i) 60 | + '\n') 61 | self._mState = constants.eNotMe 62 | break 63 | elif codingState == constants.eItsMe: 64 | self._mState = constants.eFoundIt 65 | break 66 | elif codingState == constants.eStart: 67 | charLen = self._mCodingSM.get_current_charlen() 68 | if i == 0: 69 | self._mLastChar[1] = aBuf[0] 70 | self._mContextAnalyzer.feed(self._mLastChar[2 - charLen:], 71 | charLen) 72 | self._mDistributionAnalyzer.feed(self._mLastChar, charLen) 73 | else: 74 | self._mContextAnalyzer.feed(aBuf[i + 1 - charLen:i + 3 75 | - charLen], charLen) 76 | self._mDistributionAnalyzer.feed(aBuf[i - 1:i + 1], 77 | charLen) 78 | 79 | self._mLastChar[0] = aBuf[aLen - 1] 80 | 81 | if self.get_state() == constants.eDetecting: 82 | if (self._mContextAnalyzer.got_enough_data() and 83 | (self.get_confidence() > constants.SHORTCUT_THRESHOLD)): 84 | self._mState = constants.eFoundIt 85 | 86 | return self.get_state() 87 | 88 | def get_confidence(self): 89 | contxtCf = self._mContextAnalyzer.get_confidence() 90 | distribCf = self._mDistributionAnalyzer.get_confidence() 91 | return max(contxtCf, distribCf) 92 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/charade/utf8prober.py: -------------------------------------------------------------------------------- 1 | ######################## BEGIN LICENSE BLOCK ######################## 2 | # The Original Code is mozilla.org code. 3 | # 4 | # The Initial Developer of the Original Code is 5 | # Netscape Communications Corporation. 6 | # Portions created by the Initial Developer are Copyright (C) 1998 7 | # the Initial Developer. All Rights Reserved. 8 | # 9 | # Contributor(s): 10 | # Mark Pilgrim - port to Python 11 | # 12 | # This library is free software; you can redistribute it and/or 13 | # modify it under the terms of the GNU Lesser General Public 14 | # License as published by the Free Software Foundation; either 15 | # version 2.1 of the License, or (at your option) any later version. 16 | # 17 | # This library is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | # Lesser General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU Lesser General Public 23 | # License along with this library; if not, write to the Free Software 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 | # 02110-1301 USA 26 | ######################### END LICENSE BLOCK ######################### 27 | 28 | from . import constants 29 | from .charsetprober import CharSetProber 30 | from .codingstatemachine import CodingStateMachine 31 | from .mbcssm import UTF8SMModel 32 | 33 | ONE_CHAR_PROB = 0.5 34 | 35 | 36 | class UTF8Prober(CharSetProber): 37 | def __init__(self): 38 | CharSetProber.__init__(self) 39 | self._mCodingSM = CodingStateMachine(UTF8SMModel) 40 | self.reset() 41 | 42 | def reset(self): 43 | CharSetProber.reset(self) 44 | self._mCodingSM.reset() 45 | self._mNumOfMBChar = 0 46 | 47 | def get_charset_name(self): 48 | return "utf-8" 49 | 50 | def feed(self, aBuf): 51 | for c in aBuf: 52 | codingState = self._mCodingSM.next_state(c) 53 | if codingState == constants.eError: 54 | self._mState = constants.eNotMe 55 | break 56 | elif codingState == constants.eItsMe: 57 | self._mState = constants.eFoundIt 58 | break 59 | elif codingState == constants.eStart: 60 | if self._mCodingSM.get_current_charlen() >= 2: 61 | self._mNumOfMBChar += 1 62 | 63 | if self.get_state() == constants.eDetecting: 64 | if self.get_confidence() > constants.SHORTCUT_THRESHOLD: 65 | self._mState = constants.eFoundIt 66 | 67 | return self.get_state() 68 | 69 | def get_confidence(self): 70 | unlike = 0.99 71 | if self._mNumOfMBChar < 6: 72 | for i in range(0, self._mNumOfMBChar): 73 | unlike = unlike * ONE_CHAR_PROB 74 | return 1.0 - unlike 75 | else: 76 | return unlike 77 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/urllib3/__init__.py: -------------------------------------------------------------------------------- 1 | # urllib3/__init__.py 2 | # Copyright 2008-2012 Andrey Petrov and contributors (see CONTRIBUTORS.txt) 3 | # 4 | # This module is part of urllib3 and is released under 5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php 6 | 7 | """ 8 | urllib3 - Thread-safe connection pooling and re-using. 9 | """ 10 | 11 | __author__ = 'Andrey Petrov (andrey.petrov@shazow.net)' 12 | __license__ = 'MIT' 13 | __version__ = 'dev' 14 | 15 | from .connectionpool import ( 16 | HTTPConnectionPool, 17 | HTTPSConnectionPool, 18 | connection_from_url 19 | ) 20 | 21 | from . import exceptions 22 | from .filepost import encode_multipart_formdata 23 | from .poolmanager import PoolManager, ProxyManager, proxy_from_url 24 | from .response import HTTPResponse 25 | from .util import make_headers, get_host 26 | 27 | 28 | # Set default logging handler to avoid "No handler found" warnings. 29 | import logging 30 | 31 | try: # Python 2.7+ 32 | from logging import NullHandler 33 | except ImportError: 34 | class NullHandler(logging.Handler): 35 | def emit(self, record): 36 | pass 37 | 38 | logging.getLogger(__name__).addHandler(NullHandler()) 39 | 40 | 41 | def add_stderr_logger(level=logging.DEBUG): 42 | """ 43 | Helper for quickly adding a StreamHandler to the logger. Useful for 44 | debugging. 45 | 46 | Returns the handler after adding it. 47 | """ 48 | # This method needs to be in this __init__.py to get the __name__ correct 49 | # even if urllib3 is vendored within another package. 50 | logger = logging.getLogger(__name__) 51 | handler = logging.StreamHandler() 52 | handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s')) 53 | logger.addHandler(handler) 54 | logger.setLevel(level) 55 | logger.debug('Added an stderr logging handler to logger: %s' % __name__) 56 | return handler 57 | 58 | # ... Clean up. 59 | del NullHandler 60 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/urllib3/_collections.py: -------------------------------------------------------------------------------- 1 | # urllib3/_collections.py 2 | # Copyright 2008-2012 Andrey Petrov and contributors (see CONTRIBUTORS.txt) 3 | # 4 | # This module is part of urllib3 and is released under 5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php 6 | 7 | from collections import MutableMapping 8 | from threading import Lock 9 | 10 | try: # Python 2.7+ 11 | from collections import OrderedDict 12 | except ImportError: 13 | from .packages.ordered_dict import OrderedDict 14 | 15 | __all__ = ['RecentlyUsedContainer'] 16 | 17 | _Null = object() 18 | 19 | 20 | class RecentlyUsedContainer(MutableMapping): 21 | """ 22 | Provides a thread-safe dict-like container which maintains up to 23 | ``maxsize`` keys while throwing away the least-recently-used keys beyond 24 | ``maxsize``. 25 | 26 | :param maxsize: 27 | Maximum number of recent elements to retain. 28 | 29 | :param dispose_func: 30 | Every time an item is evicted from the container, 31 | ``dispose_func(value)`` is called. Callback which will get called 32 | """ 33 | 34 | ContainerCls = OrderedDict 35 | 36 | def __init__(self, maxsize=10, dispose_func=None): 37 | self._maxsize = maxsize 38 | self.dispose_func = dispose_func 39 | 40 | self._container = self.ContainerCls() 41 | self._lock = Lock() 42 | 43 | def __getitem__(self, key): 44 | # Re-insert the item, moving it to the end of the eviction line. 45 | with self._lock: 46 | item = self._container.pop(key) 47 | self._container[key] = item 48 | return item 49 | 50 | def __setitem__(self, key, value): 51 | evicted_value = _Null 52 | with self._lock: 53 | # Possibly evict the existing value of 'key' 54 | evicted_value = self._container.get(key, _Null) 55 | self._container[key] = value 56 | 57 | # If we didn't evict an existing value, we might have to evict the 58 | # least recently used item from the beginning of the container. 59 | if len(self._container) > self._maxsize: 60 | _key, evicted_value = self._container.popitem(last=False) 61 | 62 | if self.dispose_func and evicted_value is not _Null: 63 | self.dispose_func(evicted_value) 64 | 65 | def __delitem__(self, key): 66 | with self._lock: 67 | value = self._container.pop(key) 68 | 69 | if self.dispose_func: 70 | self.dispose_func(value) 71 | 72 | def __len__(self): 73 | with self._lock: 74 | return len(self._container) 75 | 76 | def __iter__(self): 77 | raise NotImplementedError('Iteration over this class is unlikely to be threadsafe.') 78 | 79 | def clear(self): 80 | with self._lock: 81 | # Copy pointers to all values, then wipe the mapping 82 | # under Python 2, this copies the list of values twice :-| 83 | values = list(self._container.values()) 84 | self._container.clear() 85 | 86 | if self.dispose_func: 87 | for value in values: 88 | self.dispose_func(value) 89 | 90 | def keys(self): 91 | with self._lock: 92 | return self._container.keys() 93 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/urllib3/contrib/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/requests/packages/urllib3/contrib/__init__.py -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/urllib3/exceptions.py: -------------------------------------------------------------------------------- 1 | # urllib3/exceptions.py 2 | # Copyright 2008-2012 Andrey Petrov and contributors (see CONTRIBUTORS.txt) 3 | # 4 | # This module is part of urllib3 and is released under 5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php 6 | 7 | 8 | ## Base Exceptions 9 | 10 | class HTTPError(Exception): 11 | "Base exception used by this module." 12 | pass 13 | 14 | 15 | class PoolError(HTTPError): 16 | "Base exception for errors caused within a pool." 17 | 18 | def __init__(self, pool, message): 19 | self.pool = pool 20 | HTTPError.__init__(self, "%s: %s" % (pool, message)) 21 | 22 | def __reduce__(self): 23 | # For pickling purposes. 24 | return self.__class__, (None, self.url) 25 | 26 | 27 | class SSLError(HTTPError): 28 | "Raised when SSL certificate fails in an HTTPS connection." 29 | pass 30 | 31 | 32 | class DecodeError(HTTPError): 33 | "Raised when automatic decoding based on Content-Type fails." 34 | pass 35 | 36 | 37 | ## Leaf Exceptions 38 | 39 | class MaxRetryError(PoolError): 40 | "Raised when the maximum number of retries is exceeded." 41 | 42 | def __init__(self, pool, url, reason=None): 43 | self.reason = reason 44 | 45 | message = "Max retries exceeded with url: %s" % url 46 | if reason: 47 | message += " (Caused by %s: %s)" % (type(reason), reason) 48 | else: 49 | message += " (Caused by redirect)" 50 | 51 | PoolError.__init__(self, pool, message) 52 | self.url = url 53 | 54 | 55 | class HostChangedError(PoolError): 56 | "Raised when an existing pool gets a request for a foreign host." 57 | 58 | def __init__(self, pool, url, retries=3): 59 | message = "Tried to open a foreign host with url: %s" % url 60 | PoolError.__init__(self, pool, message) 61 | 62 | self.url = url 63 | self.retries = retries 64 | 65 | 66 | class TimeoutError(PoolError): 67 | "Raised when a socket timeout occurs." 68 | pass 69 | 70 | 71 | class EmptyPoolError(PoolError): 72 | "Raised when a pool runs out of connections and no more are allowed." 73 | pass 74 | 75 | 76 | class ClosedPoolError(PoolError): 77 | "Raised when a request enters a pool after the pool has been closed." 78 | pass 79 | 80 | 81 | class LocationParseError(ValueError, HTTPError): 82 | "Raised when get_host or similar fails to parse the URL input." 83 | 84 | def __init__(self, location): 85 | message = "Failed to parse: %s" % location 86 | HTTPError.__init__(self, message) 87 | 88 | self.location = location 89 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/urllib3/filepost.py: -------------------------------------------------------------------------------- 1 | # urllib3/filepost.py 2 | # Copyright 2008-2012 Andrey Petrov and contributors (see CONTRIBUTORS.txt) 3 | # 4 | # This module is part of urllib3 and is released under 5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php 6 | 7 | import codecs 8 | import mimetypes 9 | 10 | from uuid import uuid4 11 | from io import BytesIO 12 | 13 | from .packages import six 14 | from .packages.six import b 15 | 16 | writer = codecs.lookup('utf-8')[3] 17 | 18 | 19 | def choose_boundary(): 20 | """ 21 | Our embarassingly-simple replacement for mimetools.choose_boundary. 22 | """ 23 | return uuid4().hex 24 | 25 | 26 | def get_content_type(filename): 27 | return mimetypes.guess_type(filename)[0] or 'application/octet-stream' 28 | 29 | 30 | def iter_fields(fields): 31 | """ 32 | Iterate over fields. 33 | 34 | Supports list of (k, v) tuples and dicts. 35 | """ 36 | if isinstance(fields, dict): 37 | return ((k, v) for k, v in six.iteritems(fields)) 38 | 39 | return ((k, v) for k, v in fields) 40 | 41 | 42 | def encode_multipart_formdata(fields, boundary=None): 43 | """ 44 | Encode a dictionary of ``fields`` using the multipart/form-data MIME format. 45 | 46 | :param fields: 47 | Dictionary of fields or list of (key, value) or (key, value, MIME type) 48 | field tuples. The key is treated as the field name, and the value as 49 | the body of the form-data bytes. If the value is a tuple of two 50 | elements, then the first element is treated as the filename of the 51 | form-data section and a suitable MIME type is guessed based on the 52 | filename. If the value is a tuple of three elements, then the third 53 | element is treated as an explicit MIME type of the form-data section. 54 | 55 | Field names and filenames must be unicode. 56 | 57 | :param boundary: 58 | If not specified, then a random boundary will be generated using 59 | :func:`mimetools.choose_boundary`. 60 | """ 61 | body = BytesIO() 62 | if boundary is None: 63 | boundary = choose_boundary() 64 | 65 | for fieldname, value in iter_fields(fields): 66 | body.write(b('--%s\r\n' % (boundary))) 67 | 68 | if isinstance(value, tuple): 69 | if len(value) == 3: 70 | filename, data, content_type = value 71 | else: 72 | filename, data = value 73 | content_type = get_content_type(filename) 74 | writer(body).write('Content-Disposition: form-data; name="%s"; ' 75 | 'filename="%s"\r\n' % (fieldname, filename)) 76 | body.write(b('Content-Type: %s\r\n\r\n' % 77 | (content_type,))) 78 | else: 79 | data = value 80 | writer(body).write('Content-Disposition: form-data; name="%s"\r\n' 81 | % (fieldname)) 82 | body.write(b'\r\n') 83 | 84 | if isinstance(data, int): 85 | data = str(data) # Backwards compatibility 86 | 87 | if isinstance(data, six.text_type): 88 | writer(body).write(data) 89 | else: 90 | body.write(data) 91 | 92 | body.write(b'\r\n') 93 | 94 | body.write(b('--%s--\r\n' % (boundary))) 95 | 96 | content_type = b('multipart/form-data; boundary=%s' % boundary) 97 | 98 | return body.getvalue(), content_type 99 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/urllib3/packages/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | 3 | from . import ssl_match_hostname 4 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/packages/urllib3/packages/ssl_match_hostname/__init__.py: -------------------------------------------------------------------------------- 1 | """The match_hostname() function from Python 3.2, essential when using SSL.""" 2 | 3 | import re 4 | 5 | __version__ = '3.2.2' 6 | 7 | 8 | class CertificateError(ValueError): 9 | pass 10 | 11 | 12 | def _dnsname_to_pat(dn): 13 | pats = [] 14 | for frag in dn.split(r'.'): 15 | if frag == '*': 16 | # When '*' is a fragment by itself, it matches a non-empty dotless 17 | # fragment. 18 | pats.append('[^.]+') 19 | else: 20 | # Otherwise, '*' matches any dotless fragment. 21 | frag = re.escape(frag) 22 | pats.append(frag.replace(r'\*', '[^.]*')) 23 | return re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE) 24 | 25 | 26 | def match_hostname(cert, hostname): 27 | """Verify that *cert* (in decoded format as returned by 28 | SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 rules 29 | are mostly followed, but IP addresses are not accepted for *hostname*. 30 | 31 | CertificateError is raised on failure. On success, the function 32 | returns nothing. 33 | """ 34 | if not cert: 35 | raise ValueError("empty or no certificate") 36 | dnsnames = [] 37 | san = cert.get('subjectAltName', ()) 38 | for key, value in san: 39 | if key == 'DNS': 40 | if _dnsname_to_pat(value).match(hostname): 41 | return 42 | dnsnames.append(value) 43 | if not dnsnames: 44 | # The subject is only checked when there is no dNSName entry 45 | # in subjectAltName 46 | for sub in cert.get('subject', ()): 47 | for key, value in sub: 48 | # XXX according to RFC 2818, the most specific Common Name 49 | # must be used. 50 | if key == 'commonName': 51 | if _dnsname_to_pat(value).match(hostname): 52 | return 53 | dnsnames.append(value) 54 | if len(dnsnames) > 1: 55 | raise CertificateError("hostname %r " 56 | "doesn't match either of %s" 57 | % (hostname, ', '.join(map(repr, dnsnames)))) 58 | elif len(dnsnames) == 1: 59 | raise CertificateError("hostname %r " 60 | "doesn't match %r" 61 | % (hostname, dnsnames[0])) 62 | else: 63 | raise CertificateError("no appropriate commonName or " 64 | "subjectAltName fields were found") 65 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/status_codes.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from .structures import LookupDict 4 | 5 | _codes = { 6 | 7 | # Informational. 8 | 100: ('continue',), 9 | 101: ('switching_protocols',), 10 | 102: ('processing',), 11 | 103: ('checkpoint',), 12 | 122: ('uri_too_long', 'request_uri_too_long'), 13 | 200: ('ok', 'okay', 'all_ok', 'all_okay', 'all_good', '\\o/', '✓'), 14 | 201: ('created',), 15 | 202: ('accepted',), 16 | 203: ('non_authoritative_info', 'non_authoritative_information'), 17 | 204: ('no_content',), 18 | 205: ('reset_content', 'reset'), 19 | 206: ('partial_content', 'partial'), 20 | 207: ('multi_status', 'multiple_status', 'multi_stati', 'multiple_stati'), 21 | 208: ('im_used',), 22 | 23 | # Redirection. 24 | 300: ('multiple_choices',), 25 | 301: ('moved_permanently', 'moved', '\\o-'), 26 | 302: ('found',), 27 | 303: ('see_other', 'other'), 28 | 304: ('not_modified',), 29 | 305: ('use_proxy',), 30 | 306: ('switch_proxy',), 31 | 307: ('temporary_redirect', 'temporary_moved', 'temporary'), 32 | 308: ('resume_incomplete', 'resume'), 33 | 34 | # Client Error. 35 | 400: ('bad_request', 'bad'), 36 | 401: ('unauthorized',), 37 | 402: ('payment_required', 'payment'), 38 | 403: ('forbidden',), 39 | 404: ('not_found', '-o-'), 40 | 405: ('method_not_allowed', 'not_allowed'), 41 | 406: ('not_acceptable',), 42 | 407: ('proxy_authentication_required', 'proxy_auth', 'proxy_authentication'), 43 | 408: ('request_timeout', 'timeout'), 44 | 409: ('conflict',), 45 | 410: ('gone',), 46 | 411: ('length_required',), 47 | 412: ('precondition_failed', 'precondition'), 48 | 413: ('request_entity_too_large',), 49 | 414: ('request_uri_too_large',), 50 | 415: ('unsupported_media_type', 'unsupported_media', 'media_type'), 51 | 416: ('requested_range_not_satisfiable', 'requested_range', 'range_not_satisfiable'), 52 | 417: ('expectation_failed',), 53 | 418: ('im_a_teapot', 'teapot', 'i_am_a_teapot'), 54 | 422: ('unprocessable_entity', 'unprocessable'), 55 | 423: ('locked',), 56 | 424: ('failed_dependency', 'dependency'), 57 | 425: ('unordered_collection', 'unordered'), 58 | 426: ('upgrade_required', 'upgrade'), 59 | 428: ('precondition_required', 'precondition'), 60 | 429: ('too_many_requests', 'too_many'), 61 | 431: ('header_fields_too_large', 'fields_too_large'), 62 | 444: ('no_response', 'none'), 63 | 449: ('retry_with', 'retry'), 64 | 450: ('blocked_by_windows_parental_controls', 'parental_controls'), 65 | 499: ('client_closed_request',), 66 | 67 | # Server Error. 68 | 500: ('internal_server_error', 'server_error', '/o\\', '✗'), 69 | 501: ('not_implemented',), 70 | 502: ('bad_gateway',), 71 | 503: ('service_unavailable', 'unavailable'), 72 | 504: ('gateway_timeout',), 73 | 505: ('http_version_not_supported', 'http_version'), 74 | 506: ('variant_also_negotiates',), 75 | 507: ('insufficient_storage',), 76 | 509: ('bandwidth_limit_exceeded', 'bandwidth'), 77 | 510: ('not_extended',), 78 | } 79 | 80 | codes = LookupDict(name='status_codes') 81 | 82 | for (code, titles) in list(_codes.items()): 83 | for title in titles: 84 | setattr(codes, title, code) 85 | if not title.startswith('\\'): 86 | setattr(codes, title.upper(), code) 87 | -------------------------------------------------------------------------------- /NZBmegasearch/requests/structures.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | requests.structures 5 | ~~~~~~~~~~~~~~~~~~~ 6 | 7 | Data structures that power Requests. 8 | 9 | """ 10 | 11 | import os 12 | from itertools import islice 13 | 14 | 15 | class IteratorProxy(object): 16 | """docstring for IteratorProxy""" 17 | 18 | def __init__(self, i): 19 | self.i = i 20 | # self.i = chain.from_iterable(i) 21 | 22 | def __iter__(self): 23 | return self.i 24 | 25 | def __len__(self): 26 | if hasattr(self.i, '__len__'): 27 | return len(self.i) 28 | if hasattr(self.i, 'len'): 29 | return self.i.len 30 | if hasattr(self.i, 'fileno'): 31 | return os.fstat(self.i.fileno()).st_size 32 | 33 | def read(self, n): 34 | return "".join(islice(self.i, None, n)) 35 | 36 | 37 | class CaseInsensitiveDict(dict): 38 | """Case-insensitive Dictionary 39 | 40 | For example, ``headers['content-encoding']`` will return the 41 | value of a ``'Content-Encoding'`` response header.""" 42 | 43 | @property 44 | def lower_keys(self): 45 | if not hasattr(self, '_lower_keys') or not self._lower_keys: 46 | self._lower_keys = dict((k.lower(), k) for k in list(self.keys())) 47 | return self._lower_keys 48 | 49 | def _clear_lower_keys(self): 50 | if hasattr(self, '_lower_keys'): 51 | self._lower_keys.clear() 52 | 53 | def __setitem__(self, key, value): 54 | dict.__setitem__(self, key, value) 55 | self._clear_lower_keys() 56 | 57 | def __delitem__(self, key): 58 | dict.__delitem__(self, self.lower_keys.get(key.lower(), key)) 59 | self._lower_keys.clear() 60 | 61 | def __contains__(self, key): 62 | return key.lower() in self.lower_keys 63 | 64 | def __getitem__(self, key): 65 | # We allow fall-through here, so values default to None 66 | if key in self: 67 | return dict.__getitem__(self, self.lower_keys[key.lower()]) 68 | 69 | def get(self, key, default=None): 70 | if key in self: 71 | return self[key] 72 | else: 73 | return default 74 | 75 | 76 | class LookupDict(dict): 77 | """Dictionary lookup object.""" 78 | 79 | def __init__(self, name=None): 80 | self.name = name 81 | super(LookupDict, self).__init__() 82 | 83 | def __repr__(self): 84 | return '' % (self.name) 85 | 86 | def __getitem__(self, key): 87 | # We allow fall-through here, so values default to None 88 | 89 | return self.__dict__.get(key, None) 90 | 91 | def get(self, key, default=None): 92 | return self.__dict__.get(key, default) 93 | -------------------------------------------------------------------------------- /NZBmegasearch/static/arrow-down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/arrow-down.png -------------------------------------------------------------------------------- /NZBmegasearch/static/cfg_cp_offline.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/cfg_cp_offline.jpg -------------------------------------------------------------------------------- /NZBmegasearch/static/cfg_offline.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/cfg_offline.jpg -------------------------------------------------------------------------------- /NZBmegasearch/static/cp_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/cp_logo.png -------------------------------------------------------------------------------- /NZBmegasearch/static/error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/error.png -------------------------------------------------------------------------------- /NZBmegasearch/static/error_hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/error_hover.png -------------------------------------------------------------------------------- /NZBmegasearch/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/favicon.ico -------------------------------------------------------------------------------- /NZBmegasearch/static/imdb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/imdb.png -------------------------------------------------------------------------------- /NZBmegasearch/static/loadingicon.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/loadingicon.gif -------------------------------------------------------------------------------- /NZBmegasearch/static/log.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/log.png -------------------------------------------------------------------------------- /NZBmegasearch/static/nzb2_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/nzb2_16.png -------------------------------------------------------------------------------- /NZBmegasearch/static/nzb2_16_no.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/nzb2_16_no.png -------------------------------------------------------------------------------- /NZBmegasearch/static/nzb2_16_ok.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/nzb2_16_ok.png -------------------------------------------------------------------------------- /NZBmegasearch/static/off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/off.png -------------------------------------------------------------------------------- /NZBmegasearch/static/ok.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/ok.png -------------------------------------------------------------------------------- /NZBmegasearch/static/ok_hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/ok_hover.png -------------------------------------------------------------------------------- /NZBmegasearch/static/options.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/options.png -------------------------------------------------------------------------------- /NZBmegasearch/static/predb_1st.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/predb_1st.png -------------------------------------------------------------------------------- /NZBmegasearch/static/predb_2nd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/predb_2nd.png -------------------------------------------------------------------------------- /NZBmegasearch/static/reset.css: -------------------------------------------------------------------------------- 1 | /* http://meyerweb.com/eric/tools/css/reset/ 2 | v2.0 | 20110126 3 | License: none (public domain) 4 | */ 5 | 6 | html, body, div, span, applet, object, iframe, 7 | h1, h2, h3, h4, h5, h6, p, blockquote, pre, 8 | a, abbr, acronym, address, big, cite, code, 9 | del, dfn, em, img, ins, kbd, q, s, samp, 10 | small, strike, strong, sub, sup, tt, var, 11 | b, u, i, center, 12 | dl, dt, dd, ol, ul, li, 13 | fieldset, form, label, legend, 14 | table, caption, tbody, tfoot, thead, tr, th, td, 15 | article, aside, canvas, details, embed, 16 | figure, figcaption, footer, header, hgroup, 17 | menu, nav, output, ruby, section, summary, 18 | time, mark, audio, video { 19 | margin: 0; 20 | padding: 0; 21 | border: 0; 22 | font-size: 100%; 23 | font: inherit; 24 | vertical-align: baseline; 25 | } 26 | 27 | /* HTML5 display-role reset for older browsers */ 28 | article, aside, details, figcaption, figure, 29 | footer, header, hgroup, menu, nav, section { 30 | display: block; 31 | } 32 | 33 | body { 34 | line-height: 1; 35 | } 36 | 37 | ol, ul { 38 | list-style: none; 39 | } 40 | 41 | blockquote, q { 42 | quotes: none; 43 | } 44 | 45 | blockquote:before, blockquote:after, 46 | q:before, q:after { 47 | content: ''; 48 | content: none; 49 | } 50 | 51 | table { 52 | border-collapse: collapse; 53 | border-spacing: 0; 54 | } -------------------------------------------------------------------------------- /NZBmegasearch/static/restart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/restart.png -------------------------------------------------------------------------------- /NZBmegasearch/static/sab2_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/sab2_16.png -------------------------------------------------------------------------------- /NZBmegasearch/static/sab2_16_no.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/sab2_16_no.png -------------------------------------------------------------------------------- /NZBmegasearch/static/sab2_16_ok.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/sab2_16_ok.png -------------------------------------------------------------------------------- /NZBmegasearch/static/sb_cp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/sb_cp.png -------------------------------------------------------------------------------- /NZBmegasearch/static/show_config.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/show_config.jpg -------------------------------------------------------------------------------- /NZBmegasearch/static/show_search.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/show_search.jpg -------------------------------------------------------------------------------- /NZBmegasearch/static/sick_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/sick_logo.png -------------------------------------------------------------------------------- /NZBmegasearch/static/thetvdb16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/thetvdb16.png -------------------------------------------------------------------------------- /NZBmegasearch/static/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/static/title.png -------------------------------------------------------------------------------- /NZBmegasearch/templates/api.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NZBMegasearch 6 | NZBMegasearch Feed 7 | https://github.com/Mirabis/usntssearch 8 | en-gb 9 | 0byte 10 | 11 | 12 | https://github.com/Mirabis/usntssearch 13 | NZBMegasearch 14 | https://github.com/pillone/usntssearch 15 | Visit https://github.com/Mirabis/usntssearch - We stand on the shoulders of giants 16 | 17 | 18 | 19 | 20 | {% for row in results -%} 21 | 22 | {{ row['title'] }} 23 | {{ row['encodedurl'] }} 24 | {{ row['url'] }} 25 | {{ row['providerurl'] }} 26 | {{ row['age'] }} 27 | {{ row['title'] }} -- NZBMegasearch: {{ row['providertitle'] }} 28 | 29 | 30 | 31 | 32 | {% if typeres == 1 -%} 33 | TV 34 | 35 | {%- endif %} 36 | 37 | {% if typeres == 0 -%} 38 | Movies 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | {%- endif %} 59 | 60 | 61 | 62 | {%- endfor %} 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /NZBmegasearch/templates/api_default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NZBMegasearch 6 | NZBMegasearch Feed 7 | https://github.com/pillone/usntssearch 8 | en-gb 9 | 0byte 10 | 11 | 12 | https://github.com/pillone/usntssearch 13 | NZBMegasearch 14 | https://github.com/pillone/usntssearch 15 | Visit https://github.com/pillone/usntssearch - We stand on the shoulders of giants 16 | 17 | 18 | 19 | 20 | World.NZB.Megasearch.Tour.S01E01 21 | http://bogusurl.bog/details/1234567890123432523523 22 | http://bogusurl.bog/getnzb/1234567890123432523523.nzb&i=470&r=438204209348230 23 | http://bogusurl.info/details/1234567890123432523523#comments 24 | Mon, 1 Jan 1970 00:00:00 +0000 25 | TV > SD 26 | World.NZB.Megasearch.Tour.S01E01-0byte 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | World.NZB.Megasearch.Tour.S01E02 36 | http://bogusurl.bog/details/1234567890123432523523 37 | http://bogusurl.bog/getnzb/1234567890123432523523.nzb&i=470&r=438204209348230 38 | http://bogusurl.info/details/1234567890123432523523#comments 39 | Mon, 1 Jan 1970 00:00:00 +0000 40 | TV > SD 41 | World.NZB.Megasearch.Tour.S01E02-0byte 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /NZBmegasearch/templates/api_error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /NZBmegasearch/templates/connectinfo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NZB MegasearcH 6 | 7 | 8 | 9 | 10 |
11 | 12 |
13 |

14 |

Connection to SICKBEARD 15 |
16 | 17 | Sickbeard connectivity is always active.
18 | In Sickbeard: go to Config/Search Providers and add a custom Newznab provider, no API key needed (unless explicitly set in the config).
19 | 20 |

21 |
22 | 23 |
24 |

25 |

Connection to COUCHPOTATO 26 |
27 | 28 | Couchpotato connectivity is always active.
29 | In Couchpotato: go to Settings/Providers and add a custom Newznab provider with API key 123 (any key number will work unless explicitly set in the config).
30 | Below is an example of NZBMegasearcH configured with port 5000: 31 |
32 | 33 |

34 | 35 |
36 | 37 |
38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /NZBmegasearch/templates/legal.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NZB MegasearcH 6 | 7 | 8 | 9 | 10 |
11 | 12 |
13 |

14 |

Legal/DMCA 15 |
16 | This site does not store any NZB or XML regarding content posted on newsgroups. 17 | No usenet servers are accessed or crawled. 18 | 19 |

20 | This site consists of an automated search engine that 21 | only queries, without storing, available information present in other websites. 22 |

23 | 24 | Zero content is stored on this site. There is no database at all. 25 | Each search result is compiled on the fly. Moreover, we do not store search results.
26 | We are not responsible of the content listed on the crawled web indeces. 27 |
28 |
29 | We merely act as a data transport mechanism. 30 | We do not host any of the indexed content that you see on this site. 31 | We do not provide access to copyrighted material.
32 |
33 | 34 | Please note that all the DMCA requests have to be made to the crawled websites clearly specified 35 | in each line of result list. They host the NZB files. We do not store NZB. 36 | Send an email to XXXX@XXXX for DMCA requests, they 37 | will be dealt with accordingly and you will receive a response within 72 hours. 38 | In the vast majority of cases, we require requests to be made via postal mail. 39 | Please email the above address to find out the relevant agent address, 40 | which can change depending on your country of operation. Requests via email are 41 | possible, but will require an agreement to be made between XXXX and the 42 | copyright holder (or valid agent), in regards to what constitutes a valid notification - as well 43 | as outlining a process that makes all parties happy. 44 | 45 | 46 | 47 |

48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /NZBmegasearch/templates/loginfo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NZB MegasearcH 6 | 7 | 8 | 9 | 10 | 11 |
12 |
13 | NZBmegasearcH 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
>> Log
23 |
24 | 25 |
26 | 27 |
28 |
29 |

30 | {% for lgi in loginfo -%} 31 | {{ lgi}}
32 | {% endfor %} 33 |

34 |
35 |
36 |
37 | 38 | 39 | -------------------------------------------------------------------------------- /NZBmegasearch/templates/restart.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | NZB MegasearcH 8 | 9 | 10 | 11 | 12 |
13 | 14 |
15 |

16 |

17 |

18 | 19 |
20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /NZBmegasearch/templates/rss.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | NZBMegasearch feed 4 | https://github.com/pillone/usntssearch 5 | 6 | Latest newsgroup posts as indexed by NZBMegasearch 7 | 8 | 9 | A NZB metasearch engine 10 | 11 | Tue, 13 Aug 2013 18:59:59 GMT 12 | 20 13 | 14 | {% for row in results -%} 15 | 16 | {{ row['title'] }} 17 | 18 | {{ row['title'] }} -- NZBMegasearch: {{ row['providertitle'] }} 19 | 20 | {{ row['age'] }} 21 | {{ row['url'] }} 22 | 23 | 24 | {%- endfor %} 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /NZBmegasearch/vernum.num: -------------------------------------------------------------------------------- 1 | 80801102808011028080110280801102 0.56 -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = '0.8.3' 2 | -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/contrib/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | werkzeug.contrib 4 | ~~~~~~~~~~~~~~~~ 5 | 6 | Contains user-submitted code that other users may find useful, but which 7 | is not part of the Werkzeug core. Anyone can write code for inclusion in 8 | the `contrib` package. All modules in this package are distributed as an 9 | add-on library and thus are not part of Werkzeug itself. 10 | 11 | This file itself is mostly for informational purposes and to tell the 12 | Python interpreter that `contrib` is a package. 13 | 14 | :copyright: (c) 2011 by the Werkzeug Team, see AUTHORS for more details. 15 | :license: BSD, see LICENSE for more details. 16 | """ 17 | -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/contrib/limiter.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | werkzeug.contrib.limiter 4 | ~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | A middleware that limits incoming data. This works around problems with 7 | Trac_ or Django_ because those directly stream into the memory. 8 | 9 | .. _Trac: http://trac.edgewall.org/ 10 | .. _Django: http://www.djangoproject.com/ 11 | 12 | :copyright: (c) 2011 by the Werkzeug Team, see AUTHORS for more details. 13 | :license: BSD, see LICENSE for more details. 14 | """ 15 | from warnings import warn 16 | 17 | from ..wsgi import LimitedStream 18 | 19 | 20 | class StreamLimitMiddleware(object): 21 | """Limits the input stream to a given number of bytes. This is useful if 22 | you have a WSGI application that reads form data into memory (django for 23 | example) and you don't want users to harm the server by uploading tons of 24 | data. 25 | 26 | Default is 10MB 27 | """ 28 | 29 | def __init__(self, app, maximum_size=1024 * 1024 * 10): 30 | self.app = app 31 | self.maximum_size = maximum_size 32 | 33 | def __call__(self, environ, start_response): 34 | limit = min(self.maximum_size, int(environ.get('CONTENT_LENGTH') or 0)) 35 | environ['wsgi.input'] = LimitedStream(environ['wsgi.input'], limit) 36 | return self.app(environ, start_response) 37 | -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/contrib/testtools.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | werkzeug.contrib.testtools 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | This module implements extended wrappers for simplified testing. 7 | 8 | `TestResponse` 9 | A response wrapper which adds various cached attributes for 10 | simplified assertions on various content types. 11 | 12 | :copyright: (c) 2011 by the Werkzeug Team, see AUTHORS for more details. 13 | :license: BSD, see LICENSE for more details. 14 | """ 15 | from ..utils import cached_property, import_string 16 | from ..wrappers import Response 17 | 18 | from warnings import warn 19 | 20 | warn(DeprecationWarning('werkzeug.contrib.testtools is deprecated and ' 21 | 'will be removed with Werkzeug 1.0')) 22 | 23 | 24 | class ContentAccessors(object): 25 | """ 26 | A mixin class for response objects that provides a couple of useful 27 | accessors for unittesting. 28 | """ 29 | 30 | def xml(self): 31 | """Get an etree if possible.""" 32 | if 'xml' not in self.mimetype: 33 | raise AttributeError( 34 | 'Not a XML response (Content-Type: %s)' 35 | % self.mimetype) 36 | for module in ['xml.etree.ElementTree', 'ElementTree', 37 | 'elementtree.ElementTree']: 38 | etree = import_string(module, silent=True) 39 | if etree is not None: 40 | return etree.XML(self.body) 41 | raise RuntimeError('You must have ElementTree installed ' 42 | 'to use TestResponse.xml') 43 | 44 | xml = cached_property(xml) 45 | 46 | def lxml(self): 47 | """Get an lxml etree if possible.""" 48 | if ('html' not in self.mimetype and 'xml' not in self.mimetype): 49 | raise AttributeError('Not an HTML/XML response') 50 | from lxml import etree 51 | 52 | try: 53 | from lxml.html import fromstring 54 | except ImportError: 55 | fromstring = etree.HTML 56 | if self.mimetype == 'text/html': 57 | return fromstring(self.data) 58 | return etree.XML(self.data) 59 | 60 | lxml = cached_property(lxml) 61 | 62 | def json(self): 63 | """Get the result of simplejson.loads if possible.""" 64 | if 'json' not in self.mimetype: 65 | raise AttributeError('Not a JSON response') 66 | try: 67 | from simplejson import loads 68 | except ImportError: 69 | from json import loads 70 | return loads(self.data) 71 | 72 | json = cached_property(json) 73 | 74 | 75 | class TestResponse(Response, ContentAccessors): 76 | """Pass this to `werkzeug.test.Client` for easier unittesting.""" 77 | -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/debug/shared/console.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/debug/shared/console.png -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/debug/shared/less.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/debug/shared/less.png -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/debug/shared/more.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/debug/shared/more.png -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/debug/shared/source.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/debug/shared/source.png -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/debug/shared/ubuntu.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/debug/shared/ubuntu.ttf -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/posixemulation.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | r""" 3 | werkzeug.posixemulation 4 | ~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Provides a POSIX emulation for some features that are relevant to 7 | web applications. The main purpose is to simplify support for 8 | systems such as Windows NT that are not 100% POSIX compatible. 9 | 10 | Currently this only implements a :func:`rename` function that 11 | follows POSIX semantics. Eg: if the target file already exists it 12 | will be replaced without asking. 13 | 14 | This module was introduced in 0.6.1 and is not a public interface. 15 | It might become one in later versions of Werkzeug. 16 | 17 | :copyright: (c) 2011 by the Werkzeug Team, see AUTHORS for more details. 18 | :license: BSD, see LICENSE for more details. 19 | """ 20 | import sys 21 | import os 22 | import errno 23 | import time 24 | import random 25 | 26 | can_rename_open_file = False 27 | if os.name == 'nt': # pragma: no cover 28 | _rename = lambda src, dst: False 29 | _rename_atomic = lambda src, dst: False 30 | 31 | try: 32 | import ctypes 33 | 34 | _MOVEFILE_REPLACE_EXISTING = 0x1 35 | _MOVEFILE_WRITE_THROUGH = 0x8 36 | _MoveFileEx = ctypes.windll.kernel32.MoveFileExW 37 | 38 | def _rename(src, dst): 39 | if not isinstance(src, unicode): 40 | src = unicode(src, sys.getfilesystemencoding()) 41 | if not isinstance(dst, unicode): 42 | dst = unicode(dst, sys.getfilesystemencoding()) 43 | if _rename_atomic(src, dst): 44 | return True 45 | retry = 0 46 | rv = False 47 | while not rv and retry < 100: 48 | rv = _MoveFileEx(src, dst, _MOVEFILE_REPLACE_EXISTING | 49 | _MOVEFILE_WRITE_THROUGH) 50 | if not rv: 51 | time.sleep(0.001) 52 | retry += 1 53 | return rv 54 | 55 | # new in Vista and Windows Server 2008 56 | _CreateTransaction = ctypes.windll.ktmw32.CreateTransaction 57 | _CommitTransaction = ctypes.windll.ktmw32.CommitTransaction 58 | _MoveFileTransacted = ctypes.windll.kernel32.MoveFileTransactedW 59 | _CloseHandle = ctypes.windll.kernel32.CloseHandle 60 | can_rename_open_file = True 61 | 62 | def _rename_atomic(src, dst): 63 | ta = _CreateTransaction(None, 0, 0, 0, 0, 1000, 'Werkzeug rename') 64 | if ta == -1: 65 | return False 66 | try: 67 | retry = 0 68 | rv = False 69 | while not rv and retry < 100: 70 | rv = _MoveFileTransacted(src, dst, None, None, 71 | _MOVEFILE_REPLACE_EXISTING | 72 | _MOVEFILE_WRITE_THROUGH, ta) 73 | if rv: 74 | rv = _CommitTransaction(ta) 75 | break 76 | else: 77 | time.sleep(0.001) 78 | retry += 1 79 | return rv 80 | finally: 81 | _CloseHandle(ta) 82 | except Exception: 83 | pass 84 | 85 | def rename(src, dst): 86 | # Try atomic or pseudo-atomic rename 87 | if _rename(src, dst): 88 | return 89 | # Fall back to "move away and replace" 90 | try: 91 | os.rename(src, dst) 92 | except OSError, e: 93 | if e.errno != errno.EEXIST: 94 | raise 95 | old = "%s-%08x" % (dst, random.randint(0, sys.maxint)) 96 | os.rename(dst, old) 97 | os.rename(src, dst) 98 | try: 99 | os.unlink(old) 100 | except Exception: 101 | pass 102 | else: 103 | rename = os.rename 104 | can_rename_open_file = True 105 | -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/compat.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | werkzeug.testsuite.compat 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Ensure that old stuff does not break on update. 7 | 8 | :copyright: (c) 2011 by Armin Ronacher. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | import unittest 12 | import warnings 13 | from werkzeug.testsuite import WerkzeugTestCase 14 | 15 | from werkzeug.wrappers import Response 16 | from werkzeug.test import create_environ 17 | 18 | 19 | class CompatTestCase(WerkzeugTestCase): 20 | def test_old_imports(self): 21 | from werkzeug.utils import Headers, MultiDict, CombinedMultiDict, \ 22 | Headers, EnvironHeaders 23 | from werkzeug.http import Accept, MIMEAccept, CharsetAccept, \ 24 | LanguageAccept, ETags, HeaderSet, WWWAuthenticate, \ 25 | Authorization 26 | 27 | def test_exposed_werkzeug_mod(self): 28 | import werkzeug 29 | 30 | for key in werkzeug.__all__: 31 | # deprecated, skip it 32 | if key in ('templates', 'Template'): 33 | continue 34 | getattr(werkzeug, key) 35 | 36 | def test_fix_headers_in_response(self): 37 | # ignore some warnings werkzeug emits for backwards compat 38 | for msg in ['called into deprecated fix_headers', 39 | 'fix_headers changed behavior']: 40 | warnings.filterwarnings('ignore', message=msg, 41 | category=DeprecationWarning) 42 | 43 | class MyResponse(Response): 44 | def fix_headers(self, environ): 45 | Response.fix_headers(self, environ) 46 | self.headers['x-foo'] = "meh" 47 | 48 | myresp = MyResponse('Foo') 49 | resp = Response.from_app(myresp, create_environ(method='GET')) 50 | assert resp.headers['x-foo'] == 'meh' 51 | assert resp.data == 'Foo' 52 | 53 | warnings.resetwarnings() 54 | 55 | 56 | def suite(): 57 | suite = unittest.TestSuite() 58 | suite.addTest(unittest.makeSuite(CompatTestCase)) 59 | return suite 60 | -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/contrib/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | werkzeug.testsuite.contrib 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Tests the contrib modules. 7 | 8 | :copyright: (c) 2011 by Armin Ronacher. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | import unittest 12 | from werkzeug.testsuite import iter_suites 13 | 14 | 15 | def suite(): 16 | suite = unittest.TestSuite() 17 | for other_suite in iter_suites(__name__): 18 | suite.addTest(other_suite) 19 | return suite 20 | -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/contrib/iterio.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | werkzeug.testsuite.iterio 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Tests the iterio object. 7 | 8 | :copyright: (c) 2011 by Armin Ronacher. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | import unittest 12 | 13 | from werkzeug.testsuite import WerkzeugTestCase 14 | from werkzeug.contrib.iterio import IterIO, greenlet 15 | 16 | 17 | class IterOTestSuite(WerkzeugTestCase): 18 | def test_basic(self): 19 | io = IterIO(["Hello", "World", "1", "2", "3"]) 20 | assert io.tell() == 0 21 | assert io.read(2) == "He" 22 | assert io.tell() == 2 23 | assert io.read(3) == "llo" 24 | assert io.tell() == 5 25 | io.seek(0) 26 | assert io.read(5) == "Hello" 27 | assert io.tell() == 5 28 | assert io._buf == "Hello" 29 | assert io.read() == "World123" 30 | assert io.tell() == 13 31 | io.close() 32 | assert io.closed 33 | 34 | io = IterIO(["Hello\n", "World!"]) 35 | assert io.readline() == 'Hello\n' 36 | assert io._buf == 'Hello\n' 37 | assert io.read() == 'World!' 38 | assert io._buf == 'Hello\nWorld!' 39 | assert io.tell() == 12 40 | io.seek(0) 41 | assert io.readlines() == ['Hello\n', 'World!'] 42 | 43 | io = IterIO(["foo\n", "bar"]) 44 | io.seek(-4, 2) 45 | assert io.read(4) == '\nbar' 46 | 47 | self.assert_raises(IOError, io.seek, 2, 100) 48 | io.close() 49 | self.assert_raises(ValueError, io.read) 50 | 51 | 52 | class IterITestSuite(WerkzeugTestCase): 53 | def test_basic(self): 54 | def producer(out): 55 | out.write('1\n') 56 | out.write('2\n') 57 | out.flush() 58 | out.write('3\n') 59 | 60 | iterable = IterIO(producer) 61 | self.assert_equal(iterable.next(), '1\n2\n') 62 | self.assert_equal(iterable.next(), '3\n') 63 | self.assert_raises(StopIteration, iterable.next) 64 | 65 | 66 | def suite(): 67 | suite = unittest.TestSuite() 68 | suite.addTest(unittest.makeSuite(IterOTestSuite)) 69 | if greenlet is not None: 70 | suite.addTest(unittest.makeSuite(IterITestSuite)) 71 | return suite 72 | -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/contrib/securecookie.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | werkzeug.testsuite.securecookie 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Tests the secure cookie. 7 | 8 | :copyright: (c) 2011 by Armin Ronacher. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | import unittest 12 | 13 | from werkzeug.testsuite import WerkzeugTestCase 14 | 15 | from werkzeug.utils import parse_cookie 16 | from werkzeug.wrappers import Request, Response 17 | from werkzeug.contrib.securecookie import SecureCookie 18 | 19 | 20 | class SecureCookieTestCase(WerkzeugTestCase): 21 | def test_basic_support(self): 22 | c = SecureCookie(secret_key='foo') 23 | assert c.new 24 | print c.modified, c.should_save 25 | assert not c.modified 26 | assert not c.should_save 27 | c['x'] = 42 28 | assert c.modified 29 | assert c.should_save 30 | s = c.serialize() 31 | 32 | c2 = SecureCookie.unserialize(s, 'foo') 33 | assert c is not c2 34 | assert not c2.new 35 | assert not c2.modified 36 | assert not c2.should_save 37 | assert c2 == c 38 | 39 | c3 = SecureCookie.unserialize(s, 'wrong foo') 40 | assert not c3.modified 41 | assert not c3.new 42 | assert c3 == {} 43 | 44 | def test_wrapper_support(self): 45 | req = Request.from_values() 46 | resp = Response() 47 | c = SecureCookie.load_cookie(req, secret_key='foo') 48 | assert c.new 49 | c['foo'] = 42 50 | assert c.secret_key == 'foo' 51 | c.save_cookie(resp) 52 | 53 | req = Request.from_values(headers={ 54 | 'Cookie': 'session="%s"' % parse_cookie(resp.headers['set-cookie'])['session'] 55 | }) 56 | c2 = SecureCookie.load_cookie(req, secret_key='foo') 57 | assert not c2.new 58 | assert c2 == c 59 | 60 | 61 | def suite(): 62 | suite = unittest.TestSuite() 63 | suite.addTest(unittest.makeSuite(SecureCookieTestCase)) 64 | return suite 65 | -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/contrib/sessions.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | werkzeug.testsuite.sessions 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Added tests for the sessions. 7 | 8 | :copyright: (c) 2011 by Armin Ronacher. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | import unittest 12 | import shutil 13 | 14 | from werkzeug.testsuite import WerkzeugTestCase 15 | 16 | from werkzeug.contrib.sessions import FilesystemSessionStore 17 | 18 | from tempfile import mkdtemp, gettempdir 19 | 20 | 21 | class SessionTestCase(WerkzeugTestCase): 22 | def setup(self): 23 | self.session_folder = mkdtemp() 24 | 25 | def teardown(self): 26 | shutil.rmtree(self.session_folder) 27 | 28 | def test_default_tempdir(self): 29 | store = FilesystemSessionStore() 30 | assert store.path == gettempdir() 31 | 32 | def test_basic_fs_sessions(self): 33 | store = FilesystemSessionStore(self.session_folder) 34 | x = store.new() 35 | assert x.new 36 | assert not x.modified 37 | x['foo'] = [1, 2, 3] 38 | assert x.modified 39 | store.save(x) 40 | 41 | x2 = store.get(x.sid) 42 | assert not x2.new 43 | assert not x2.modified 44 | assert x2 is not x 45 | assert x2 == x 46 | x2['test'] = 3 47 | assert x2.modified 48 | assert not x2.new 49 | store.save(x2) 50 | 51 | x = store.get(x.sid) 52 | store.delete(x) 53 | x2 = store.get(x.sid) 54 | # the session is not new when it was used previously. 55 | assert not x2.new 56 | 57 | def test_renewing_fs_session(self): 58 | store = FilesystemSessionStore(self.session_folder, renew_missing=True) 59 | x = store.new() 60 | store.save(x) 61 | store.delete(x) 62 | x2 = store.get(x.sid) 63 | assert x2.new 64 | 65 | def test_fs_session_lising(self): 66 | store = FilesystemSessionStore(self.session_folder, renew_missing=True) 67 | sessions = set() 68 | for x in xrange(10): 69 | sess = store.new() 70 | store.save(sess) 71 | sessions.add(sess.sid) 72 | 73 | listed_sessions = set(store.list()) 74 | assert sessions == listed_sessions 75 | 76 | 77 | def suite(): 78 | suite = unittest.TestSuite() 79 | suite.addTest(unittest.makeSuite(SessionTestCase)) 80 | return suite 81 | -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/contrib/wrappers.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | werkzeug.testsuite.contrib.wrappers 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Added tests for the sessions. 7 | 8 | :copyright: (c) 2011 by Armin Ronacher. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | 12 | from __future__ import with_statement 13 | 14 | import unittest 15 | 16 | from werkzeug.testsuite import WerkzeugTestCase 17 | 18 | from werkzeug.contrib import wrappers 19 | from werkzeug import routing 20 | from werkzeug.wrappers import Request, Response 21 | 22 | 23 | class WrappersTestCase(WerkzeugTestCase): 24 | def test_reverse_slash_behavior(self): 25 | class MyRequest(wrappers.ReverseSlashBehaviorRequestMixin, Request): 26 | pass 27 | 28 | req = MyRequest.from_values('/foo/bar', 'http://example.com/test') 29 | assert req.url == 'http://example.com/test/foo/bar' 30 | assert req.path == 'foo/bar' 31 | assert req.script_root == '/test/' 32 | 33 | # make sure the routing system works with the slashes in 34 | # reverse order as well. 35 | map = routing.Map([routing.Rule('/foo/bar', endpoint='foo')]) 36 | adapter = map.bind_to_environ(req.environ) 37 | assert adapter.match() == ('foo', {}) 38 | adapter = map.bind(req.host, req.script_root) 39 | assert adapter.match(req.path) == ('foo', {}) 40 | 41 | def test_dynamic_charset_request_mixin(self): 42 | class MyRequest(wrappers.DynamicCharsetRequestMixin, Request): 43 | pass 44 | 45 | env = {'CONTENT_TYPE': 'text/html'} 46 | req = MyRequest(env) 47 | assert req.charset == 'latin1' 48 | 49 | env = {'CONTENT_TYPE': 'text/html; charset=utf-8'} 50 | req = MyRequest(env) 51 | assert req.charset == 'utf-8' 52 | 53 | env = {'CONTENT_TYPE': 'application/octet-stream'} 54 | req = MyRequest(env) 55 | assert req.charset == 'latin1' 56 | assert req.url_charset == 'latin1' 57 | 58 | MyRequest.url_charset = 'utf-8' 59 | env = {'CONTENT_TYPE': 'application/octet-stream'} 60 | req = MyRequest(env) 61 | assert req.charset == 'latin1' 62 | assert req.url_charset == 'utf-8' 63 | 64 | def return_ascii(x): 65 | return "ascii" 66 | 67 | env = {'CONTENT_TYPE': 'text/plain; charset=x-weird-charset'} 68 | req = MyRequest(env) 69 | req.unknown_charset = return_ascii 70 | assert req.charset == 'ascii' 71 | assert req.url_charset == 'utf-8' 72 | 73 | def test_dynamic_charset_response_mixin(self): 74 | class MyResponse(wrappers.DynamicCharsetResponseMixin, Response): 75 | default_charset = 'utf-7' 76 | 77 | resp = MyResponse(mimetype='text/html') 78 | assert resp.charset == 'utf-7' 79 | resp.charset = 'utf-8' 80 | assert resp.charset == 'utf-8' 81 | assert resp.mimetype == 'text/html' 82 | assert resp.mimetype_params == {'charset': 'utf-8'} 83 | resp.mimetype_params['charset'] = 'iso-8859-15' 84 | assert resp.charset == 'iso-8859-15' 85 | resp.data = u'Hällo Wörld' 86 | assert ''.join(resp.iter_encoded()) == \ 87 | u'Hällo Wörld'.encode('iso-8859-15') 88 | del resp.headers['content-type'] 89 | try: 90 | resp.charset = 'utf-8' 91 | except TypeError, e: 92 | pass 93 | else: 94 | assert False, 'expected type error on charset setting without ct' 95 | 96 | 97 | def suite(): 98 | suite = unittest.TestSuite() 99 | suite.addTest(unittest.makeSuite(WrappersTestCase)) 100 | return suite 101 | -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/exceptions.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | werkzeug.testsuite.exceptions 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | The tests for the exception classes. 7 | 8 | TODO: 9 | 10 | - This is undertested. HTML is never checked 11 | 12 | :copyright: (c) 2011 by Armin Ronacher. 13 | :license: BSD, see LICENSE for more details. 14 | """ 15 | import unittest 16 | 17 | from werkzeug.testsuite import WerkzeugTestCase 18 | 19 | from werkzeug import exceptions 20 | from werkzeug.wrappers import Response 21 | 22 | 23 | class ExceptionsTestCase(WerkzeugTestCase): 24 | def test_proxy_exception(self): 25 | orig_resp = Response('Hello World') 26 | try: 27 | exceptions.abort(orig_resp) 28 | except exceptions.HTTPException, e: 29 | resp = e.get_response({}) 30 | else: 31 | self.fail('exception not raised') 32 | self.assert_(resp is orig_resp) 33 | self.assert_equal(resp.data, 'Hello World') 34 | 35 | def test_aborter(self): 36 | abort = exceptions.abort 37 | self.assert_raises(exceptions.BadRequest, abort, 400) 38 | self.assert_raises(exceptions.Unauthorized, abort, 401) 39 | self.assert_raises(exceptions.Forbidden, abort, 403) 40 | self.assert_raises(exceptions.NotFound, abort, 404) 41 | self.assert_raises(exceptions.MethodNotAllowed, abort, 405, ['GET', 'HEAD']) 42 | self.assert_raises(exceptions.NotAcceptable, abort, 406) 43 | self.assert_raises(exceptions.RequestTimeout, abort, 408) 44 | self.assert_raises(exceptions.Gone, abort, 410) 45 | self.assert_raises(exceptions.LengthRequired, abort, 411) 46 | self.assert_raises(exceptions.PreconditionFailed, abort, 412) 47 | self.assert_raises(exceptions.RequestEntityTooLarge, abort, 413) 48 | self.assert_raises(exceptions.RequestURITooLarge, abort, 414) 49 | self.assert_raises(exceptions.UnsupportedMediaType, abort, 415) 50 | self.assert_raises(exceptions.InternalServerError, abort, 500) 51 | self.assert_raises(exceptions.NotImplemented, abort, 501) 52 | self.assert_raises(exceptions.BadGateway, abort, 502) 53 | self.assert_raises(exceptions.ServiceUnavailable, abort, 503) 54 | 55 | myabort = exceptions.Aborter({1: exceptions.NotFound}) 56 | self.assert_raises(LookupError, myabort, 404) 57 | self.assert_raises(exceptions.NotFound, myabort, 1) 58 | 59 | myabort = exceptions.Aborter(extra={1: exceptions.NotFound}) 60 | self.assert_raises(exceptions.NotFound, myabort, 404) 61 | self.assert_raises(exceptions.NotFound, myabort, 1) 62 | 63 | def test_exception_repr(self): 64 | exc = exceptions.NotFound() 65 | self.assert_equal(unicode(exc), '404: Not Found') 66 | self.assert_equal(repr(exc), "") 67 | 68 | exc = exceptions.NotFound('Not There') 69 | self.assert_equal(unicode(exc), '404: Not There') 70 | self.assert_equal(repr(exc), "") 71 | 72 | def test_special_exceptions(self): 73 | exc = exceptions.MethodNotAllowed(['GET', 'HEAD', 'POST']) 74 | h = dict(exc.get_headers({})) 75 | self.assert_equal(h['Allow'], 'GET, HEAD, POST') 76 | self.assert_('The method DELETE is not allowed' in exc.get_description({ 77 | 'REQUEST_METHOD': 'DELETE' 78 | })) 79 | 80 | 81 | def suite(): 82 | suite = unittest.TestSuite() 83 | suite.addTest(unittest.makeSuite(ExceptionsTestCase)) 84 | return suite 85 | -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/internal.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | werkzeug.testsuite.internal 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Internal tests. 7 | 8 | :copyright: (c) 2011 by Armin Ronacher. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | import unittest 12 | 13 | from datetime import datetime 14 | from warnings import filterwarnings, resetwarnings 15 | 16 | from werkzeug.testsuite import WerkzeugTestCase 17 | from werkzeug.wrappers import Request, Response 18 | 19 | from werkzeug import _internal as internal 20 | from werkzeug.test import create_environ 21 | 22 | 23 | class InternalTestCase(WerkzeugTestCase): 24 | def test_date_to_unix(self): 25 | assert internal._date_to_unix(datetime(1970, 1, 1)) == 0 26 | assert internal._date_to_unix(datetime(1970, 1, 1, 1, 0, 0)) == 3600 27 | assert internal._date_to_unix(datetime(1970, 1, 1, 1, 1, 1)) == 3661 28 | x = datetime(2010, 2, 15, 16, 15, 39) 29 | assert internal._date_to_unix(x) == 1266250539 30 | 31 | def test_easteregg(self): 32 | req = Request.from_values('/?macgybarchakku') 33 | resp = Response.force_type(internal._easteregg(None), req) 34 | assert 'About Werkzeug' in resp.data 35 | assert 'the Swiss Army knife of Python web development' in resp.data 36 | 37 | def test_wrapper_internals(self): 38 | req = Request.from_values(data={'foo': 'bar'}, method='POST') 39 | req._load_form_data() 40 | assert req.form.to_dict() == {'foo': 'bar'} 41 | 42 | # second call does not break 43 | req._load_form_data() 44 | assert req.form.to_dict() == {'foo': 'bar'} 45 | 46 | # check reprs 47 | assert repr(req) == "" 48 | resp = Response() 49 | assert repr(resp) == '' 50 | resp.data = 'Hello World!' 51 | assert repr(resp) == '' 52 | resp.response = iter(['Test']) 53 | assert repr(resp) == '' 54 | 55 | # unicode data does not set content length 56 | response = Response([u'Hällo Wörld']) 57 | headers = response.get_wsgi_headers(create_environ()) 58 | assert 'Content-Length' not in headers 59 | 60 | response = Response(['Hällo Wörld']) 61 | headers = response.get_wsgi_headers(create_environ()) 62 | assert 'Content-Length' in headers 63 | 64 | # check for internal warnings 65 | filterwarnings('error', category=Warning) 66 | response = Response() 67 | environ = create_environ() 68 | response.response = 'What the...?' 69 | self.assert_raises(Warning, lambda: list(response.iter_encoded())) 70 | self.assert_raises(Warning, lambda: list(response.get_app_iter(environ))) 71 | response.direct_passthrough = True 72 | self.assert_raises(Warning, lambda: list(response.iter_encoded())) 73 | self.assert_raises(Warning, lambda: list(response.get_app_iter(environ))) 74 | resetwarnings() 75 | 76 | 77 | def suite(): 78 | suite = unittest.TestSuite() 79 | suite.addTest(unittest.makeSuite(InternalTestCase)) 80 | return suite 81 | -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/local.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | werkzeug.testsuite.local 4 | ~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Local and local proxy tests. 7 | 8 | :copyright: (c) 2011 by Armin Ronacher. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | import time 12 | import unittest 13 | from threading import Thread 14 | 15 | from werkzeug.testsuite import WerkzeugTestCase 16 | 17 | from werkzeug import local 18 | 19 | 20 | class LocalTestCase(WerkzeugTestCase): 21 | def test_basic_local(self): 22 | l = local.Local() 23 | l.foo = 0 24 | values = [] 25 | 26 | def value_setter(idx): 27 | time.sleep(0.01 * idx) 28 | l.foo = idx 29 | time.sleep(0.02) 30 | values.append(l.foo) 31 | 32 | threads = [Thread(target=value_setter, args=(x,)) 33 | for x in [1, 2, 3]] 34 | for thread in threads: 35 | thread.start() 36 | time.sleep(0.2) 37 | assert sorted(values) == [1, 2, 3] 38 | 39 | def delfoo(): 40 | del l.foo 41 | 42 | delfoo() 43 | self.assert_raises(AttributeError, lambda: l.foo) 44 | self.assert_raises(AttributeError, delfoo) 45 | 46 | local.release_local(l) 47 | 48 | def test_local_release(self): 49 | loc = local.Local() 50 | loc.foo = 42 51 | local.release_local(loc) 52 | assert not hasattr(loc, 'foo') 53 | 54 | ls = local.LocalStack() 55 | ls.push(42) 56 | local.release_local(ls) 57 | assert ls.top is None 58 | 59 | def test_local_proxy(self): 60 | foo = [] 61 | ls = local.LocalProxy(lambda: foo) 62 | ls.append(42) 63 | ls.append(23) 64 | ls[1:] = [1, 2, 3] 65 | assert foo == [42, 1, 2, 3] 66 | assert repr(foo) == repr(ls) 67 | assert foo[0] == 42 68 | foo += [1] 69 | assert list(foo) == [42, 1, 2, 3, 1] 70 | 71 | def test_local_stack(self): 72 | ident = local.get_ident() 73 | 74 | ls = local.LocalStack() 75 | assert ident not in ls._local.__storage__ 76 | assert ls.top is None 77 | ls.push(42) 78 | assert ident in ls._local.__storage__ 79 | assert ls.top == 42 80 | ls.push(23) 81 | assert ls.top == 23 82 | ls.pop() 83 | assert ls.top == 42 84 | ls.pop() 85 | assert ls.top is None 86 | assert ls.pop() is None 87 | assert ls.pop() is None 88 | 89 | proxy = ls() 90 | ls.push([1, 2]) 91 | assert proxy == [1, 2] 92 | ls.push((1, 2)) 93 | assert proxy == (1, 2) 94 | ls.pop() 95 | ls.pop() 96 | assert repr(proxy) == '' 97 | 98 | assert ident not in ls._local.__storage__ 99 | 100 | def test_local_proxies_with_callables(self): 101 | foo = 42 102 | ls = local.LocalProxy(lambda: foo) 103 | assert ls == 42 104 | foo = [23] 105 | ls.append(42) 106 | assert ls == [23, 42] 107 | assert foo == [23, 42] 108 | 109 | def test_custom_idents(self): 110 | ident = 0 111 | loc = local.Local() 112 | stack = local.LocalStack() 113 | mgr = local.LocalManager([loc, stack], ident_func=lambda: ident) 114 | 115 | loc.foo = 42 116 | stack.push({'foo': 42}) 117 | ident = 1 118 | loc.foo = 23 119 | stack.push({'foo': 23}) 120 | ident = 0 121 | assert loc.foo == 42 122 | assert stack.top['foo'] == 42 123 | stack.pop() 124 | assert stack.top is None 125 | ident = 1 126 | assert loc.foo == 23 127 | assert stack.top['foo'] == 23 128 | stack.pop() 129 | assert stack.top is None 130 | 131 | 132 | def suite(): 133 | suite = unittest.TestSuite() 134 | suite.addTest(unittest.makeSuite(LocalTestCase)) 135 | return suite 136 | -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/collect.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Hacky helper application to collect form data. 4 | """ 5 | from werkzeug.serving import run_simple 6 | from werkzeug.wrappers import Request, Response 7 | 8 | 9 | def copy_stream(request): 10 | from os import mkdir 11 | from time import time 12 | 13 | folder = 'request-%d' % time() 14 | mkdir(folder) 15 | environ = request.environ 16 | f = file(folder + '/request.txt', 'wb+') 17 | f.write(environ['wsgi.input'].read(int(environ['CONTENT_LENGTH']))) 18 | f.flush() 19 | f.seek(0) 20 | environ['wsgi.input'] = f 21 | request.stat_folder = folder 22 | 23 | 24 | def stats(request): 25 | copy_stream(request) 26 | f1 = request.files['file1'] 27 | f2 = request.files['file2'] 28 | text = request.form['text'] 29 | f1.save(request.stat_folder + '/file1.bin') 30 | f2.save(request.stat_folder + '/file2.bin') 31 | file(request.stat_folder + '/text.txt', 'w').write(text.encode('utf-8')) 32 | return Response('Done.') 33 | 34 | 35 | def upload_file(request): 36 | return Response(''' 37 |

Upload File

38 |
39 |
40 |
41 |
42 | 43 |
44 | ''', mimetype='text/html') 45 | 46 | 47 | def application(environ, start_responseonse): 48 | request = Request(environ) 49 | if request.method == 'POST': 50 | response = stats(request) 51 | else: 52 | response = upload_file(request) 53 | return response(environ, start_responseonse) 54 | 55 | 56 | if __name__ == '__main__': 57 | run_simple('localhost', 5000, application, use_debugger=True) 58 | -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/firefox3-2png1txt/file1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/testsuite/multipart/firefox3-2png1txt/file1.png -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/firefox3-2png1txt/file2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/testsuite/multipart/firefox3-2png1txt/file2.png -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/firefox3-2png1txt/request.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/testsuite/multipart/firefox3-2png1txt/request.txt -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/firefox3-2png1txt/text.txt: -------------------------------------------------------------------------------- 1 | example text -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/firefox3-2pnglongtext/file1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/testsuite/multipart/firefox3-2pnglongtext/file1.png -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/firefox3-2pnglongtext/file2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/testsuite/multipart/firefox3-2pnglongtext/file2.png -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/firefox3-2pnglongtext/request.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/testsuite/multipart/firefox3-2pnglongtext/request.txt -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/firefox3-2pnglongtext/text.txt: -------------------------------------------------------------------------------- 1 | --long text 2 | --with boundary 3 | --lookalikes-- -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/ie6-2png1txt/file1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/testsuite/multipart/ie6-2png1txt/file1.png -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/ie6-2png1txt/file2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/testsuite/multipart/ie6-2png1txt/file2.png -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/ie6-2png1txt/request.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/testsuite/multipart/ie6-2png1txt/request.txt -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/ie6-2png1txt/text.txt: -------------------------------------------------------------------------------- 1 | ie6 sucks :-/ -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/ie7_full_path_request.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/testsuite/multipart/ie7_full_path_request.txt -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/opera8-2png1txt/file1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/testsuite/multipart/opera8-2png1txt/file1.png -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/opera8-2png1txt/file2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/testsuite/multipart/opera8-2png1txt/file2.png -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/opera8-2png1txt/request.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/testsuite/multipart/opera8-2png1txt/request.txt -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/opera8-2png1txt/text.txt: -------------------------------------------------------------------------------- 1 | blafasel öäü -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/webkit3-2png1txt/file1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/testsuite/multipart/webkit3-2png1txt/file1.png -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/webkit3-2png1txt/file2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/testsuite/multipart/webkit3-2png1txt/file2.png -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/webkit3-2png1txt/request.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mirabis/usntssearch/a45c784287303dc9c787ad2ab0c98eeb72f98836/NZBmegasearch/werkzeug/testsuite/multipart/webkit3-2png1txt/request.txt -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/multipart/webkit3-2png1txt/text.txt: -------------------------------------------------------------------------------- 1 | this is another text with ümläüts -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/res/test.txt: -------------------------------------------------------------------------------- 1 | FOUND 2 | -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/security.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | werkzeug.testsuite.security 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Tests the security helpers. 7 | 8 | :copyright: (c) 2011 by Armin Ronacher. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | import os 12 | import unittest 13 | 14 | from werkzeug.testsuite import WerkzeugTestCase 15 | 16 | from werkzeug.security import check_password_hash, generate_password_hash, \ 17 | safe_join 18 | 19 | 20 | class SecurityTestCase(WerkzeugTestCase): 21 | def test_password_hashing(self): 22 | """Test the password hashing and password hash checking""" 23 | hash1 = generate_password_hash('default') 24 | hash2 = generate_password_hash(u'default', method='sha1') 25 | assert hash1 != hash2 26 | assert check_password_hash(hash1, 'default') 27 | assert check_password_hash(hash2, 'default') 28 | assert hash1.startswith('sha1$') 29 | assert hash2.startswith('sha1$') 30 | 31 | fakehash = generate_password_hash('default', method='plain') 32 | assert fakehash == 'plain$$default' 33 | assert check_password_hash(fakehash, 'default') 34 | 35 | mhash = generate_password_hash(u'default', method='md5') 36 | assert mhash.startswith('md5$') 37 | assert check_password_hash(mhash, 'default') 38 | 39 | legacy = 'md5$$c21f969b5f03d33d43e04f8f136e7682' 40 | assert check_password_hash(legacy, 'default') 41 | 42 | legacy = u'md5$$c21f969b5f03d33d43e04f8f136e7682' 43 | assert check_password_hash(legacy, 'default') 44 | 45 | def test_safe_join(self): 46 | """Test the safe joining helper""" 47 | assert safe_join('foo', 'bar/baz') == os.path.join('foo', 'bar/baz') 48 | assert safe_join('foo', '../bar/baz') is None 49 | if os.name == 'nt': 50 | assert safe_join('foo', 'foo\\bar') is None 51 | 52 | 53 | def suite(): 54 | suite = unittest.TestSuite() 55 | suite.addTest(unittest.makeSuite(SecurityTestCase)) 56 | return suite 57 | -------------------------------------------------------------------------------- /NZBmegasearch/werkzeug/testsuite/serving.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | werkzeug.testsuite.serving 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | Added serving tests. 7 | 8 | :copyright: (c) 2011 by Armin Ronacher. 9 | :license: BSD, see LICENSE for more details. 10 | """ 11 | import sys 12 | import time 13 | import urllib 14 | import unittest 15 | from functools import update_wrapper 16 | from StringIO import StringIO 17 | 18 | from werkzeug.testsuite import WerkzeugTestCase 19 | 20 | from werkzeug import __version__ as version, serving 21 | from werkzeug.testapp import test_app 22 | from threading import Thread 23 | 24 | real_make_server = serving.make_server 25 | 26 | 27 | def silencestderr(f): 28 | def new_func(*args, **kwargs): 29 | old_stderr = sys.stderr 30 | sys.stderr = StringIO() 31 | try: 32 | return f(*args, **kwargs) 33 | finally: 34 | sys.stderr = old_stderr 35 | 36 | return update_wrapper(new_func, f) 37 | 38 | 39 | def run_dev_server(application): 40 | servers = [] 41 | 42 | def tracking_make_server(*args, **kwargs): 43 | srv = real_make_server(*args, **kwargs) 44 | servers.append(srv) 45 | return srv 46 | 47 | serving.make_server = tracking_make_server 48 | try: 49 | t = Thread(target=serving.run_simple, args=('localhost', 0, application)) 50 | t.setDaemon(True) 51 | t.start() 52 | time.sleep(0.25) 53 | finally: 54 | serving.make_server = real_make_server 55 | if not servers: 56 | return None, None 57 | server, = servers 58 | ip, port = server.socket.getsockname()[:2] 59 | if ':' in ip: 60 | ip = '[%s]' % ip 61 | return server, '%s:%d' % (ip, port) 62 | 63 | 64 | class ServingTestCase(WerkzeugTestCase): 65 | @silencestderr 66 | def test_serving(self): 67 | server, addr = run_dev_server(test_app) 68 | rv = urllib.urlopen('http://%s/?foo=bar&baz=blah' % addr).read() 69 | assert 'WSGI Information' in rv 70 | assert 'foo=bar&baz=blah' in rv 71 | assert ('Werkzeug/%s' % version) in rv 72 | 73 | @silencestderr 74 | def test_broken_app(self): 75 | def broken_app(environ, start_response): 76 | 1 / 0 77 | 78 | server, addr = run_dev_server(broken_app) 79 | rv = urllib.urlopen('http://%s/?foo=bar&baz=blah' % addr).read() 80 | assert 'Internal Server Error' in rv 81 | 82 | 83 | def suite(): 84 | suite = unittest.TestSuite() 85 | suite.addTest(unittest.makeSuite(ServingTestCase)) 86 | return suite 87 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Doesn't seem to play ball with automation tools... thinking of an alternative/fresh start 2 | 3 | **NZBmegasearcH** 4 | ====================== 5 | 6 | *Aggregate automatically NZB search results. Easy. Quick. Clean.* 7 | 8 | NZBmegasearcH collects all your (not only) newznab-based accounts to one place. It is your meta-search engine and your SB, CP unique NZB provider. 9 | 10 | ## [Go to official NZBmegasearcH website](http://pillone.github.io/usntssearch/) 11 | 12 | All credits to the original authors. 13 | 14 | ## Updates 15 | **Changes in v0.56 (11/11/2015)** 16 | + Merged Undeadhunters NzbGet fix 17 | + Merged HackedServers rearranged search priority + tvbid (replaced) 18 | + Replaced tvbid/tvrage by tvmaze as workaround 19 | + implemented thetvdb lookup for (possible) future implementations 20 | + removal of AnimeNzb 21 | 22 | **Changes in v0.55 (3/8/2015)** 23 | + Changed default timeouts (higher) 24 | + gingadaddy is no longer set to use https 25 | + updated jQuery to 2.1.4 26 | + added option to disable url warping 27 | + changed user agents 28 | + fixed piratenzb not returning any results 29 | + merged fix from cauchy49:cauchy49-patch-api-url-with-proxy-1 30 | 31 | **Changes in v0.54** 32 | + Fix issue in tvdbid being an int and it expecting a string 33 | 34 | **Changes in v0.53 (20/5/2015)** 35 | + no longer asks for the wrong login/pw on accessing the config 36 | + Little code cleanup & reformatting 37 | + Added Anime to Newznab class 38 | + Movie without _HD/_SD will now search both 39 | + Added additional codes for XXX categories 40 | + Fix NzbDrone api Integration 41 | + Fix Sickbeard api integration 42 | + removed nzb.cc 43 | + changed Fanzub to AnimeDB 44 | + upped version numbering 45 | + changed default cache 46 | 47 | 48 | Purged older updates....More updates are available in changelog.txt of main repo 49 | 50 | website statistics 53 | 54 | --------------------------------------------------------------------------------