34 changed files with 1345 additions and 1114 deletions
@ -0,0 +1,22 @@ |
|||
from .main import BinSearch |
|||
|
|||
def start(): |
|||
return BinSearch() |
|||
|
|||
config = [{ |
|||
'name': 'binsearch', |
|||
'groups': [ |
|||
{ |
|||
'tab': 'searcher', |
|||
'subtab': 'nzb_providers', |
|||
'name': 'binsearch', |
|||
'description': 'Free provider, less accurate. See <a href="https://www.binsearch.info/">BinSearch</a>', |
|||
'options': [ |
|||
{ |
|||
'name': 'enabled', |
|||
'type': 'enabler', |
|||
}, |
|||
], |
|||
}, |
|||
], |
|||
}] |
@ -0,0 +1,99 @@ |
|||
from bs4 import BeautifulSoup |
|||
from couchpotato.core.helpers.encoding import tryUrlencode |
|||
from couchpotato.core.helpers.variable import tryInt |
|||
from couchpotato.core.logger import CPLog |
|||
from couchpotato.core.providers.nzb.base import NZBProvider |
|||
from couchpotato.environment import Env |
|||
import re |
|||
import traceback |
|||
|
|||
log = CPLog(__name__) |
|||
|
|||
|
|||
class BinSearch(NZBProvider): |
|||
|
|||
urls = { |
|||
'download': 'https://www.binsearch.info/fcgi/nzb.fcgi?q=%s', |
|||
'detail': 'https://www.binsearch.info%s', |
|||
'search': 'https://www.binsearch.info/index.php?%s', |
|||
} |
|||
|
|||
http_time_between_calls = 4 # Seconds |
|||
|
|||
def _search(self, movie, quality, results): |
|||
|
|||
q = '%s %s' % (movie['library']['identifier'], quality.get('identifier')) |
|||
arguments = tryUrlencode({ |
|||
'q': q, |
|||
'm': 'n', |
|||
'max': 250, |
|||
'adv_age': Env.setting('retention', 'nzb'), |
|||
'adv_sort': 'date', |
|||
'adv_col': 'on', |
|||
'adv_nfo': 'on', |
|||
'minsize': quality.get('size_min'), |
|||
'maxsize': quality.get('size_max'), |
|||
}) |
|||
|
|||
data = self.getHTMLData(self.urls['search'] % arguments) |
|||
|
|||
if data: |
|||
try: |
|||
|
|||
html = BeautifulSoup(data) |
|||
main_table = html.find('table', attrs = {'id':'r2'}) |
|||
|
|||
if not main_table: |
|||
return |
|||
|
|||
items = main_table.find_all('tr') |
|||
|
|||
for row in items: |
|||
title = row.find('span', attrs = {'class':'s'}) |
|||
|
|||
if not title: continue |
|||
|
|||
nzb_id = row.find('input', attrs = {'type':'checkbox'})['name'] |
|||
info = row.find('span', attrs = {'class':'d'}) |
|||
size_match = re.search('size:.(?P<size>[0-9\.]+.[GMB]+)', info.text) |
|||
|
|||
def extra_check(item): |
|||
parts = re.search('available:.(?P<parts>\d+)./.(?P<total>\d+)', info.text) |
|||
total = tryInt(parts.group('total')) |
|||
parts = tryInt(parts.group('parts')) |
|||
|
|||
if (total / parts) < 0.95 or ((total / parts) >= 0.95 and not 'par2' in info.text.lower()): |
|||
log.info2('Wrong: \'%s\', not complete: %s out of %s', (item['name'], parts, total)) |
|||
return False |
|||
|
|||
if 'requires password' in info.text.lower(): |
|||
log.info2('Wrong: \'%s\', passworded', (item['name'])) |
|||
return False |
|||
|
|||
return True |
|||
|
|||
results.append({ |
|||
'id': nzb_id, |
|||
'name': title.text, |
|||
'age': tryInt(re.search('(?P<size>\d+d)', row.find_all('td')[-1:][0].text).group('size')[:-1]), |
|||
'size': self.parseSize(size_match.group('size')), |
|||
'url': self.urls['download'] % nzb_id, |
|||
'detail_url': self.urls['detail'] % info.find('a')['href'], |
|||
'extra_check': extra_check |
|||
}) |
|||
|
|||
except: |
|||
log.error('Failed to parse HTML response from BinSearch: %s', traceback.format_exc()) |
|||
|
|||
def download(self, url = '', nzb_id = ''): |
|||
|
|||
params = {'action': 'nzb'} |
|||
params[nzb_id] = 'on' |
|||
|
|||
try: |
|||
return self.urlopen(url, params = params, show_error = False) |
|||
except: |
|||
log.error('Failed getting nzb from %s: %s', (self.getName(), traceback.format_exc())) |
|||
|
|||
return 'try_next' |
|||
|
@ -1,91 +1,37 @@ |
|||
from couchpotato.core.event import fireEvent |
|||
from couchpotato.core.helpers.encoding import tryUrlencode |
|||
from couchpotato.core.helpers.rss import RSS |
|||
from couchpotato.core.helpers.variable import tryInt |
|||
from couchpotato.core.logger import CPLog |
|||
from couchpotato.core.providers.nzb.base import NZBProvider |
|||
import json |
|||
import traceback |
|||
|
|||
log = CPLog(__name__) |
|||
|
|||
|
|||
class Nzbx(NZBProvider, RSS): |
|||
endpoint = 'https://nzbx.co/api/' |
|||
class Nzbx(NZBProvider): |
|||
|
|||
urls = { |
|||
'search': 'https://nzbx.co/api/search', |
|||
'search': 'https://nzbx.co/api/search?%s', |
|||
'details': 'https://nzbx.co/api/details?guid=%s', |
|||
'comments': 'https://nzbx.co/api/get-comments?guid=%s', |
|||
'ratings': 'https://nzbx.co/api/get-votes?guid=%s', |
|||
'downloads': 'https://nzbx.co/api/get-downloads-count?guid=%s', |
|||
'categories': 'https://nzbx.co/api/categories', |
|||
'groups': 'https://nzbx.co/api/groups', |
|||
} |
|||
|
|||
http_time_between_calls = 1 # Seconds |
|||
|
|||
def search(self, movie, quality): |
|||
results = [] |
|||
|
|||
if self.isDisabled(): |
|||
return results |
|||
def _search(self, movie, quality, results): |
|||
|
|||
# Get nbzs |
|||
arguments = tryUrlencode({ |
|||
'q': movie['library']['identifier'].replace('tt', ''), |
|||
'sf': quality.get('size_min'), |
|||
}) |
|||
url = "%s?%s" % (self.urls['search'], arguments) |
|||
|
|||
cache_key = 'nzbx.%s.%s' % (movie['library']['identifier'], quality.get('identifier')) |
|||
|
|||
data = self.getCache(cache_key, url) |
|||
|
|||
if data: |
|||
try: |
|||
try: |
|||
nzbs = json.loads(data) |
|||
except Exception, e: |
|||
log.debug('%s, %s', (self.getName(), e)) |
|||
return results |
|||
|
|||
for nzb in nzbs: |
|||
|
|||
nzbx_guid = nzb['guid'] |
|||
|
|||
def extra_score(item): |
|||
score = 0 |
|||
if item['votes']['upvotes'] > item['votes']['downvotes']: |
|||
score += 5 |
|||
return score |
|||
|
|||
new = { |
|||
'guid': nzbx_guid, |
|||
'type': 'nzb', |
|||
'provider': self.getName(), |
|||
'download': self.download, |
|||
'url': nzb['nzb'], |
|||
'name': nzb['name'], |
|||
'age': self.calculateAge(int(nzb['postdate'])), |
|||
'size': tryInt(nzb['size']) / 1024 / 1024, |
|||
'description': '', |
|||
'extra_score': extra_score, |
|||
'votes': nzb['votes'], |
|||
'check_nzb': True, |
|||
} |
|||
|
|||
is_correct_movie = fireEvent('searcher.correct_movie', |
|||
nzb = new, movie = movie, quality = quality, |
|||
imdb_results = False, single = True) |
|||
|
|||
if is_correct_movie: |
|||
new['score'] = fireEvent('score.calculate', new, movie, single = True) |
|||
results.append(new) |
|||
self.found(new) |
|||
|
|||
return results |
|||
except: |
|||
log.error('Failed to parsing %s: %s', (self.getName(), traceback.format_exc())) |
|||
|
|||
return results |
|||
|
|||
nzbs = self.getJsonData(self.urls['search'] % arguments) |
|||
|
|||
for nzb in nzbs: |
|||
|
|||
results.append({ |
|||
'id': nzb['guid'], |
|||
'url': nzb['nzb'], |
|||
'detail_url': self.urls['details'] % nzb['guid'], |
|||
'name': nzb['name'], |
|||
'age': self.calculateAge(int(nzb['postdate'])), |
|||
'size': tryInt(nzb['size']) / 1024 / 1024, |
|||
'score': 5 if nzb['votes']['upvotes'] > nzb['votes']['downvotes'] else 0 |
|||
}) |
|||
|
@ -0,0 +1,32 @@ |
|||
from .main import TorrentDay |
|||
|
|||
def start(): |
|||
return TorrentDay() |
|||
|
|||
config = [{ |
|||
'name': 'torrentday', |
|||
'groups': [ |
|||
{ |
|||
'tab': 'searcher', |
|||
'subtab': 'torrent_providers', |
|||
'name': 'TorrentDay', |
|||
'description': 'See <a href="http://www.td.af/">TorrentDay</a>', |
|||
'options': [ |
|||
{ |
|||
'name': 'enabled', |
|||
'type': 'enabler', |
|||
'default': False, |
|||
}, |
|||
{ |
|||
'name': 'username', |
|||
'default': '', |
|||
}, |
|||
{ |
|||
'name': 'password', |
|||
'default': '', |
|||
'type': 'password', |
|||
}, |
|||
], |
|||
}, |
|||
], |
|||
}] |
@ -0,0 +1,61 @@ |
|||
from couchpotato.core.helpers.encoding import tryUrlencode |
|||
from couchpotato.core.helpers.variable import tryInt |
|||
from couchpotato.core.logger import CPLog |
|||
from couchpotato.core.providers.torrent.base import TorrentProvider |
|||
|
|||
log = CPLog(__name__) |
|||
|
|||
|
|||
class TorrentDay(TorrentProvider): |
|||
|
|||
urls = { |
|||
'test': 'http://www.td.af/', |
|||
'login' : 'http://www.td.af/torrents/', |
|||
'detail': 'http://www.td.af/details.php?id=%s', |
|||
'search': 'http://www.td.af/V3/API/API.php', |
|||
'download': 'http://www.td.af/download.php/%s/%s', |
|||
} |
|||
|
|||
cat_ids = [ |
|||
([11], ['720p', '1080p']), |
|||
([1, 21, 25], ['cam', 'ts', 'dvdrip', 'tc', 'r5', 'scr', 'brrip']), |
|||
([3], ['dvdr']), |
|||
([5], ['bd50']), |
|||
] |
|||
|
|||
http_time_between_calls = 1 #seconds |
|||
|
|||
def _searchOnTitle(self, title, movie, quality, results): |
|||
|
|||
q = '"%s %s"' % (title, movie['library']['year']) |
|||
|
|||
params = { |
|||
'/browse.php?': None, |
|||
'cata': 'yes', |
|||
'jxt': 8, |
|||
'jxw': 'b', |
|||
'search': q, |
|||
} |
|||
|
|||
data = self.getJsonData(self.urls['search'], params = params, opener = self.login_opener) |
|||
try: torrents = data.get('Fs', [])[0].get('Cn', {}).get('torrents', []) |
|||
except: return |
|||
|
|||
for torrent in torrents: |
|||
results.append({ |
|||
'id': torrent['id'], |
|||
'name': torrent['name'], |
|||
'url': self.urls['download'] % (torrent['id'], torrent['fname']), |
|||
'detail_url': self.urls['detail'] % torrent['id'], |
|||
'size': self.parseSize(torrent.get('size')), |
|||
'seeders': tryInt(torrent.get('seed')), |
|||
'leechers': tryInt(torrent.get('leech')), |
|||
'download': self.loginDownload, |
|||
}) |
|||
|
|||
def getLoginParams(self): |
|||
return tryUrlencode({ |
|||
'username': self.conf('username'), |
|||
'password': self.conf('password'), |
|||
'submit': 'submit', |
|||
}) |
@ -1,9 +1,10 @@ |
|||
# -*- coding: utf-8 -*- |
|||
""" |
|||
Copyright (c) 2003-2010 Gustavo Niemeyer <gustavo@niemeyer.net> |
|||
|
|||
This module offers extensions to the standard python 2.3+ |
|||
This module offers extensions to the standard Python |
|||
datetime module. |
|||
""" |
|||
__author__ = "Gustavo Niemeyer <gustavo@niemeyer.net>" |
|||
__license__ = "PSF License" |
|||
__version__ = "1.5" |
|||
__author__ = "Tomi Pieviläinen <tomi.pievilainen@iki.fi>" |
|||
__license__ = "Simplified BSD" |
|||
__version__ = "2.1" |
|||
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,366 @@ |
|||
"""Utilities for writing code that runs on Python 2 and 3""" |
|||
|
|||
import operator |
|||
import sys |
|||
import types |
|||
|
|||
__author__ = "Benjamin Peterson <benjamin@python.org>" |
|||
__version__ = "1.2.0" |
|||
|
|||
|
|||
# True if we are running on Python 3. |
|||
PY3 = sys.version_info[0] == 3 |
|||
|
|||
if PY3: |
|||
string_types = str, |
|||
integer_types = int, |
|||
class_types = type, |
|||
text_type = str |
|||
binary_type = bytes |
|||
|
|||
MAXSIZE = sys.maxsize |
|||
else: |
|||
string_types = basestring, |
|||
integer_types = (int, long) |
|||
class_types = (type, types.ClassType) |
|||
text_type = unicode |
|||
binary_type = str |
|||
|
|||
if sys.platform == "java": |
|||
# Jython always uses 32 bits. |
|||
MAXSIZE = int((1 << 31) - 1) |
|||
else: |
|||
# It's possible to have sizeof(long) != sizeof(Py_ssize_t). |
|||
class X(object): |
|||
def __len__(self): |
|||
return 1 << 31 |
|||
try: |
|||
len(X()) |
|||
except OverflowError: |
|||
# 32-bit |
|||
MAXSIZE = int((1 << 31) - 1) |
|||
else: |
|||
# 64-bit |
|||
MAXSIZE = int((1 << 63) - 1) |
|||
del X |
|||
|
|||
|
|||
def _add_doc(func, doc): |
|||
"""Add documentation to a function.""" |
|||
func.__doc__ = doc |
|||
|
|||
|
|||
def _import_module(name): |
|||
"""Import module, returning the module after the last dot.""" |
|||
__import__(name) |
|||
return sys.modules[name] |
|||
|
|||
|
|||
class _LazyDescr(object): |
|||
|
|||
def __init__(self, name): |
|||
self.name = name |
|||
|
|||
def __get__(self, obj, tp): |
|||
result = self._resolve() |
|||
setattr(obj, self.name, result) |
|||
# This is a bit ugly, but it avoids running this again. |
|||
delattr(tp, self.name) |
|||
return result |
|||
|
|||
|
|||
class MovedModule(_LazyDescr): |
|||
|
|||
def __init__(self, name, old, new=None): |
|||
super(MovedModule, self).__init__(name) |
|||
if PY3: |
|||
if new is None: |
|||
new = name |
|||
self.mod = new |
|||
else: |
|||
self.mod = old |
|||
|
|||
def _resolve(self): |
|||
return _import_module(self.mod) |
|||
|
|||
|
|||
class MovedAttribute(_LazyDescr): |
|||
|
|||
def __init__(self, name, old_mod, new_mod, old_attr=None, new_attr=None): |
|||
super(MovedAttribute, self).__init__(name) |
|||
if PY3: |
|||
if new_mod is None: |
|||
new_mod = name |
|||
self.mod = new_mod |
|||
if new_attr is None: |
|||
if old_attr is None: |
|||
new_attr = name |
|||
else: |
|||
new_attr = old_attr |
|||
self.attr = new_attr |
|||
else: |
|||
self.mod = old_mod |
|||
if old_attr is None: |
|||
old_attr = name |
|||
self.attr = old_attr |
|||
|
|||
def _resolve(self): |
|||
module = _import_module(self.mod) |
|||
return getattr(module, self.attr) |
|||
|
|||
|
|||
|
|||
class _MovedItems(types.ModuleType): |
|||
"""Lazy loading of moved objects""" |
|||
|
|||
|
|||
_moved_attributes = [ |
|||
MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"), |
|||
MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"), |
|||
MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"), |
|||
MovedAttribute("map", "itertools", "builtins", "imap", "map"), |
|||
MovedAttribute("reload_module", "__builtin__", "imp", "reload"), |
|||
MovedAttribute("reduce", "__builtin__", "functools"), |
|||
MovedAttribute("StringIO", "StringIO", "io"), |
|||
MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"), |
|||
MovedAttribute("zip", "itertools", "builtins", "izip", "zip"), |
|||
|
|||
MovedModule("builtins", "__builtin__"), |
|||
MovedModule("configparser", "ConfigParser"), |
|||
MovedModule("copyreg", "copy_reg"), |
|||
MovedModule("http_cookiejar", "cookielib", "http.cookiejar"), |
|||
MovedModule("http_cookies", "Cookie", "http.cookies"), |
|||
MovedModule("html_entities", "htmlentitydefs", "html.entities"), |
|||
MovedModule("html_parser", "HTMLParser", "html.parser"), |
|||
MovedModule("http_client", "httplib", "http.client"), |
|||
MovedModule("BaseHTTPServer", "BaseHTTPServer", "http.server"), |
|||
MovedModule("CGIHTTPServer", "CGIHTTPServer", "http.server"), |
|||
MovedModule("SimpleHTTPServer", "SimpleHTTPServer", "http.server"), |
|||
MovedModule("cPickle", "cPickle", "pickle"), |
|||
MovedModule("queue", "Queue"), |
|||
MovedModule("reprlib", "repr"), |
|||
MovedModule("socketserver", "SocketServer"), |
|||
MovedModule("tkinter", "Tkinter"), |
|||
MovedModule("tkinter_dialog", "Dialog", "tkinter.dialog"), |
|||
MovedModule("tkinter_filedialog", "FileDialog", "tkinter.filedialog"), |
|||
MovedModule("tkinter_scrolledtext", "ScrolledText", "tkinter.scrolledtext"), |
|||
MovedModule("tkinter_simpledialog", "SimpleDialog", "tkinter.simpledialog"), |
|||
MovedModule("tkinter_tix", "Tix", "tkinter.tix"), |
|||
MovedModule("tkinter_constants", "Tkconstants", "tkinter.constants"), |
|||
MovedModule("tkinter_dnd", "Tkdnd", "tkinter.dnd"), |
|||
MovedModule("tkinter_colorchooser", "tkColorChooser", |
|||
"tkinter.colorchooser"), |
|||
MovedModule("tkinter_commondialog", "tkCommonDialog", |
|||
"tkinter.commondialog"), |
|||
MovedModule("tkinter_tkfiledialog", "tkFileDialog", "tkinter.filedialog"), |
|||
MovedModule("tkinter_font", "tkFont", "tkinter.font"), |
|||
MovedModule("tkinter_messagebox", "tkMessageBox", "tkinter.messagebox"), |
|||
MovedModule("tkinter_tksimpledialog", "tkSimpleDialog", |
|||
"tkinter.simpledialog"), |
|||
MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"), |
|||
MovedModule("winreg", "_winreg"), |
|||
] |
|||
for attr in _moved_attributes: |
|||
setattr(_MovedItems, attr.name, attr) |
|||
del attr |
|||
|
|||
moves = sys.modules["six.moves"] = _MovedItems("moves") |
|||
|
|||
|
|||
def add_move(move): |
|||
"""Add an item to six.moves.""" |
|||
setattr(_MovedItems, move.name, move) |
|||
|
|||
|
|||
def remove_move(name): |
|||
"""Remove item from six.moves.""" |
|||
try: |
|||
delattr(_MovedItems, name) |
|||
except AttributeError: |
|||
try: |
|||
del moves.__dict__[name] |
|||
except KeyError: |
|||
raise AttributeError("no such move, %r" % (name,)) |
|||
|
|||
|
|||
if PY3: |
|||
_meth_func = "__func__" |
|||
_meth_self = "__self__" |
|||
|
|||
_func_code = "__code__" |
|||
_func_defaults = "__defaults__" |
|||
|
|||
_iterkeys = "keys" |
|||
_itervalues = "values" |
|||
_iteritems = "items" |
|||
else: |
|||
_meth_func = "im_func" |
|||
_meth_self = "im_self" |
|||
|
|||
_func_code = "func_code" |
|||
_func_defaults = "func_defaults" |
|||
|
|||
_iterkeys = "iterkeys" |
|||
_itervalues = "itervalues" |
|||
_iteritems = "iteritems" |
|||
|
|||
|
|||
try: |
|||
advance_iterator = next |
|||
except NameError: |
|||
def advance_iterator(it): |
|||
return it.next() |
|||
next = advance_iterator |
|||
|
|||
|
|||
if PY3: |
|||
def get_unbound_function(unbound): |
|||
return unbound |
|||
|
|||
Iterator = object |
|||
|
|||
def callable(obj): |
|||
return any("__call__" in klass.__dict__ for klass in type(obj).__mro__) |
|||
else: |
|||
def get_unbound_function(unbound): |
|||
return unbound.im_func |
|||
|
|||
class Iterator(object): |
|||
|
|||
def next(self): |
|||
return type(self).__next__(self) |
|||
|
|||
callable = callable |
|||
_add_doc(get_unbound_function, |
|||
"""Get the function out of a possibly unbound function""") |
|||
|
|||
|
|||
get_method_function = operator.attrgetter(_meth_func) |
|||
get_method_self = operator.attrgetter(_meth_self) |
|||
get_function_code = operator.attrgetter(_func_code) |
|||
get_function_defaults = operator.attrgetter(_func_defaults) |
|||
|
|||
|
|||
def iterkeys(d): |
|||
"""Return an iterator over the keys of a dictionary.""" |
|||
return iter(getattr(d, _iterkeys)()) |
|||
|
|||
def itervalues(d): |
|||
"""Return an iterator over the values of a dictionary.""" |
|||
return iter(getattr(d, _itervalues)()) |
|||
|
|||
def iteritems(d): |
|||
"""Return an iterator over the (key, value) pairs of a dictionary.""" |
|||
return iter(getattr(d, _iteritems)()) |
|||
|
|||
|
|||
if PY3: |
|||
def b(s): |
|||
return s.encode("latin-1") |
|||
def u(s): |
|||
return s |
|||
if sys.version_info[1] <= 1: |
|||
def int2byte(i): |
|||
return bytes((i,)) |
|||
else: |
|||
# This is about 2x faster than the implementation above on 3.2+ |
|||
int2byte = operator.methodcaller("to_bytes", 1, "big") |
|||
import io |
|||
StringIO = io.StringIO |
|||
BytesIO = io.BytesIO |
|||
else: |
|||
def b(s): |
|||
return s |
|||
def u(s): |
|||
return unicode(s, "unicode_escape") |
|||
int2byte = chr |
|||
import StringIO |
|||
StringIO = BytesIO = StringIO.StringIO |
|||
_add_doc(b, """Byte literal""") |
|||
_add_doc(u, """Text literal""") |
|||
|
|||
|
|||
if PY3: |
|||
import builtins |
|||
exec_ = getattr(builtins, "exec") |
|||
|
|||
|
|||
def reraise(tp, value, tb=None): |
|||
if value.__traceback__ is not tb: |
|||
raise value.with_traceback(tb) |
|||
raise value |
|||
|
|||
|
|||
print_ = getattr(builtins, "print") |
|||
del builtins |
|||
|
|||
else: |
|||
def exec_(code, globs=None, locs=None): |
|||
"""Execute code in a namespace.""" |
|||
if globs is None: |
|||
frame = sys._getframe(1) |
|||
globs = frame.f_globals |
|||
if locs is None: |
|||
locs = frame.f_locals |
|||
del frame |
|||
elif locs is None: |
|||
locs = globs |
|||
exec("""exec code in globs, locs""") |
|||
|
|||
|
|||
exec_("""def reraise(tp, value, tb=None): |
|||
raise tp, value, tb |
|||
""") |
|||
|
|||
|
|||
def print_(*args, **kwargs): |
|||
"""The new-style print function.""" |
|||
fp = kwargs.pop("file", sys.stdout) |
|||
if fp is None: |
|||
return |
|||
def write(data): |
|||
if not isinstance(data, basestring): |
|||
data = str(data) |
|||
fp.write(data) |
|||
want_unicode = False |
|||
sep = kwargs.pop("sep", None) |
|||
if sep is not None: |
|||
if isinstance(sep, unicode): |
|||
want_unicode = True |
|||
elif not isinstance(sep, str): |
|||
raise TypeError("sep must be None or a string") |
|||
end = kwargs.pop("end", None) |
|||
if end is not None: |
|||
if isinstance(end, unicode): |
|||
want_unicode = True |
|||
elif not isinstance(end, str): |
|||
raise TypeError("end must be None or a string") |
|||
if kwargs: |
|||
raise TypeError("invalid keyword arguments to print()") |
|||
if not want_unicode: |
|||
for arg in args: |
|||
if isinstance(arg, unicode): |
|||
want_unicode = True |
|||
break |
|||
if want_unicode: |
|||
newline = unicode("\n") |
|||
space = unicode(" ") |
|||
else: |
|||
newline = "\n" |
|||
space = " " |
|||
if sep is None: |
|||
sep = space |
|||
if end is None: |
|||
end = newline |
|||
for i, arg in enumerate(args): |
|||
if i: |
|||
write(sep) |
|||
write(arg) |
|||
write(end) |
|||
|
|||
_add_doc(reraise, """Reraise an exception.""") |
|||
|
|||
|
|||
def with_metaclass(meta, base=object): |
|||
"""Create a base class with a metaclass.""" |
|||
return meta("NewBase", (base,), {}) |
Loading…
Reference in new issue