Пример #1
0
	def site_init(self):
		meta = self.api('query', meta = 'siteinfo|userinfo', 
			siprop = 'general|namespaces', uiprop = 'groups|rights')
		self.site = meta['query']['general']
		self.namespaces = dict(((i['id'], i.get('*', '')) for i in meta['query']['namespaces'].itervalues()))
		self.writeapi = 'writeapi' in self.site
			
		if self.site['generator'].startswith('MediaWiki '):
			version = self.site['generator'][10:].split('.')
			if len(version) == 2 and version[1].endswith('alpha'):
				self.version = (int(version[0]), int(version[1][:-5]), 'alpha')
			elif len(version) == 3:
				self.version = (int(version[0]), int(version[1]), int(version[2]))
			else:
				raise errors.MediaWikiVersionError('Unknown MediaWiki %s' % '.'.join(version))
		else:
			raise errors.MediaWikiVersionError('Unknown generator %s' % self.site['generator'])
		# Require 1.11 until some compatibility issues are fixed
		self.require(1, 11)
			
		userinfo = compatibility.userinfo(meta, self.require(1, 12, raise_error = False))
		self.username = userinfo['name']
		self.groups = userinfo.get('groups', [])
		self.rights = userinfo.get('rights', [])
		self.initialized = True
Пример #2
0
    def site_init(self):
        meta = self.api('query',
                        meta='siteinfo|userinfo',
                        siprop='general|namespaces',
                        uiprop='groups|rights')

        # Extract site info
        self.site = meta['query']['general']
        self.namespaces = dict(
            ((i['id'], i.get('*', ''))
             for i in meta['query']['namespaces'].itervalues()))
        self.writeapi = 'writeapi' in self.site

        # Determine version
        if self.site['generator'].startswith('MediaWiki '):
            version = self.site['generator'][10:].split('.')

            def split_num(s):
                i = 0
                while i < len(s):
                    if s[i] < '0' or s[i] > '9':
                        break
                    i += 1
                return int(s[:i]), s[i:]

            # FIXME! Fix those awful two hacks
            if len(version) == 2:
                # An alpha version
                self.version = (int(version[0]), ) + split_num(version[1])
            elif len(version) == 3 and 'rc' in version[2]:
                # Release candidate
                self.version = (int(version[0]), int(version[1]), version[2])
            elif len(version) == 3:
                # Regular y.x.z version
                self.version = (int(version[0]), int(version[1]),
                                int(version[2]))
            else:
                raise errors.MediaWikiVersionError('Unknown MediaWiki %s' %
                                                   '.'.join(version))
        else:
            raise errors.MediaWikiVersionError('Unknown generator %s' %
                                               self.site['generator'])
        # Require 1.11 until some compatibility issues are fixed
        self.require(1, 11)

        # User info
        userinfo = compatibility.userinfo(
            meta, self.require(1, 12, raise_error=False))
        self.username = userinfo['name']
        self.groups = userinfo.get('groups', [])
        self.rights = userinfo.get('rights', [])
        self.initialized = True
Пример #3
0
    def site_init(self):
        meta = self.api('query',
                        meta='siteinfo|userinfo',
                        siprop='general|namespaces',
                        uiprop='groups|rights')

        # Extract site info
        self.site = meta['query']['general']
        self.namespaces = dict(
            ((i['id'], i.get('*', ''))
             for i in meta['query']['namespaces'].itervalues()))
        self.writeapi = 'writeapi' in self.site

        # Determine version
        if self.site['generator'].startswith('MediaWiki '):
            version = self.site['generator'][10:].split('.')

            def split_num(s):
                i = 0
                while i < len(s):
                    if s[i] < '0' or s[i] > '9':
                        break
                    i += 1
                if s[i:]:
                    return (
                        int(s[:i]),
                        s[i:],
                    )
                else:
                    return (int(s[:i]), )

            self.version = sum((split_num(s) for s in version), ())

            if len(self.version) < 2:
                raise errors.MediaWikiVersionError('Unknown MediaWiki %s' %
                                                   '.'.join(version))
        else:
            raise errors.MediaWikiVersionError('Unknown generator %s' %
                                               self.site['generator'])

        # Require MediaWiki version >= 1.16
        self.require(1, 16)

        # User info
        userinfo = meta['query']['userinfo']
        self.username = userinfo['name']
        self.groups = userinfo.get('groups', [])
        self.rights = userinfo.get('rights', [])
        self.initialized = True
Пример #4
0
	def require(self, major, minor, revision = None, raise_error = True):
		if self.version is None:
			if raise_error is None: return 
			raise RuntimeError('Site %s has not yet been initialized' % repr(self))
		
		if revision is None:
			if self.version[:2] >= (major, minor):
				return True
			elif raise_error:
				raise errors.MediaWikiVersionError('Requires version %s.%s, current version is %s.%s' 
					% ((major, minor) + self.version[:2]))
			else:
				return False
		else:
			raise NotImplementedError