Beispiel #1
0
    def __init__(self,
                 host,
                 path='/w/',
                 ext='.php',
                 pool=None,
                 retry_timeout=30,
                 max_retries=25,
                 wait_callback=lambda *x: None,
                 max_lag=3,
                 compress=True,
                 force_login=True,
                 do_init=True):
        self.host = host
        self.path = path
        self.ext = ext
        self.credentials = None
        self.compress = compress

        self.retry_timeout = retry_timeout
        self.max_retries = max_retries
        self.wait_callback = wait_callback
        self.max_lag = str(max_lag)

        self.wait_tokens = weakref.WeakKeyDictionary()

        self.blocked = False
        self.hasmsg = False
        self.groups = []
        self.rights = []
        self.tokens = {}
        self.force_login = force_login

        if pool is None:
            self.connection = http.HTTPPool()
        else:
            self.connection = pool

        self.version = None

        self.pages = listing.PageList(self)
        self.categories = listing.PageList(self, namespace=14)
        self.images = listing.PageList(self, namespace=6)

        # Compat
        self.Pages = self.pages
        self.Categories = self.categories
        self.Images = self.images

        self.namespaces = self.default_namespaces
        self.writeapi = False

        self.initialized = False

        if do_init:
            try:
                self.site_init()
            except errors.APIError, e:
                # Private wiki, do init after login
                if e[0] != u'unknown_action': raise
Beispiel #2
0
    def __init__(self, host, path='/w/', ext='.php', pool=None, retry_timeout=30, max_retries=25, wait_callback=lambda *x: None,
                 max_lag=3, compress=True, force_login=True, do_init=True, custom_headers=None):
        # Setup member variables
        self.host = host
        self.path = path
        self.ext = ext
        self.credentials = None
        self.compress = compress

        self.retry_timeout = retry_timeout
        self.max_retries = max_retries
        self.wait_callback = wait_callback
        self.max_lag = str(max_lag)
        self.force_login = force_login

        # The token string => token object mapping
        self.wait_tokens = weakref.WeakKeyDictionary()

        # Site properties
        self.blocked = False    # Whether current user is blocked
        self.hasmsg = False  # Whether current user has new messages
        self.groups = []    # Groups current user belongs to
        self.rights = []    # Rights current user has
        self.tokens = {}    # Edit tokens of the current user
        self.version = None

        self.namespaces = self.default_namespaces
        self.writeapi = False
        self.custom_headers = custom_headers if custom_headers is not None else {}

        # Setup connection
        if pool is None:
            self.connection = httpmw.HTTPPool()
        else:
            self.connection = pool

        # Page generators
        self.pages = listing.PageList(self)
        self.categories = listing.PageList(self, namespace=14)
        self.images = listing.PageList(self, namespace=6)

        # Compat page generators
        self.Pages = self.pages
        self.Categories = self.categories
        self.Images = self.images

        # Initialization status
        self.initialized = False

        if do_init:
            try:
                self.site_init()
            except errors.APIError as e:
                # Private wiki, do init after login
                if e.code not in (u'unknown_action', u'readapidenied'):
                    raise
Beispiel #3
0
    def __init__(self,
                 host,
                 path='/w/',
                 ext='.php',
                 pool=None,
                 retry_timeout=30,
                 max_retries=25,
                 wait_callback=lambda *x: None,
                 clients_useragent=None,
                 max_lag=3,
                 compress=True,
                 force_login=True,
                 do_init=True,
                 httpauth=None):
        # Setup member variables
        self.host = host
        self.path = path
        self.ext = ext
        self.credentials = None
        self.compress = compress
        self.retry_timeout = retry_timeout
        self.max_retries = max_retries
        self.wait_callback = wait_callback
        self.max_lag = text_type(max_lag)
        self.force_login = force_login

        if isinstance(httpauth, (list, tuple)):
            self.httpauth = HTTPBasicAuth(*httpauth)
        elif httpauth is None or isinstance(httpauth, (AuthBase, )):
            self.httpauth = httpauth
        else:
            raise RuntimeError(
                'Authentication is not a tuple or an instance of AuthBase')

        # The token string => token object mapping
        self.wait_tokens = weakref.WeakKeyDictionary()

        # Site properties
        self.blocked = False  # Whether current user is blocked
        self.hasmsg = False  # Whether current user has new messages
        self.groups = []  # Groups current user belongs to
        self.rights = []  # Rights current user has
        self.tokens = {}  # Edit tokens of the current user
        self.version = None

        self.namespaces = self.default_namespaces
        self.writeapi = False

        # Setup connection
        if pool is None:
            self.connection = requests.Session()
            self.connection.auth = self.httpauth
            self.connection.headers[
                'User-Agent'] = 'MwClient/' + __ver__ + ' (https://github.com/mwclient/mwclient)'
            if clients_useragent:
                self.connection.headers[
                    'User-Agent'] = clients_useragent + ' - ' + self.connection.headers[
                        'User-Agent']
        else:
            self.connection = pool

        # Page generators
        self.pages = listing.PageList(self)
        self.categories = listing.PageList(self, namespace=14)
        self.images = listing.PageList(self, namespace=6)

        # Compat page generators
        self.Pages = self.pages
        self.Categories = self.categories
        self.Images = self.images

        # Initialization status
        self.initialized = False

        if do_init:
            try:
                self.site_init()
            except errors.APIError as e:
                # Private wiki, do init after login
                if e.args[0] not in (u'unknown_action', u'readapidenied'):
                    raise