<commit_before># Copyright (c) 2008 <NAME>
# see __init__.py for license details

import scout
import sys
import httplib
import urllib
from xml.dom import minidom

class ScoutModule(object):

    name = "webpin"
    desc = _("Search in packages using the webpin webservice.")
    distros = {
        'suse110' : 'openSUSE_110',
        'suse103' : 'openSUSE_103',
        'suse102' : 'openSUSE_102',
        'factory' : 'SUSE_Factory',
    }
    service_host = 'api.opensuse-community.org'
    service_baseurl = '/searchservice/Search/Simple/'


    @classmethod
    def query(cls, term, distro):
        try:
            url = cls.service_baseurl + cls.distros[distro] + '/' + urllib.quote(term)
            c = httplib.HTTPConnection(cls.service_host)
            c.connect()
            c.putrequest('GET', 'http://%s%s' % (cls.service_host, url))
            c.putheader('User-Agent', 'scout')
            c.putheader('Accept', 'text/xml')
            c.endheaders()
            r = c.getresponse()
            data = r.read()
            r.close()
            return minidom.parseString(data)
        except Exception, e:
            print _("Cannot retreive query results ... %s") % e
            return None

    @classmethod
    def fill_result(cls, root):
        scout.null_lang.install()
        result_list = [_("pkg"), _("ver"), _("arch"), _("repo"), _("files")]
        result_list2=[_("package"), _("version"), _("arch"), _("repository URL"), _("matched files")]
        scout.default_lang.install()
        result = scout.Result( result_list, result_list2 );

        for node in root.getElementsByTagName("package"):
            name = node.getElementsByTagName('name').item(0).childNodes.item(0).nodeValue
            version = node.getElementsByTagName('version').item(0).childNodes.item(0).nodeValue
            summary = node.getElementsByTagName('summary').item(0).childNodes.item(0).nodeValue
            repoURL = node.getElementsByTagName('repoURL').item(0).childNodes.item(0).nodeValue
            archs = []
            archsNode = node.getElementsByTagName('archs').item(0)
            if archsNode:
                for archNode in archsNode.getElementsByTagName('arch'):
                    archs.append(archNode.childNodes.item(0).nodeValue)
            archs = ' '.join(archs)
            fileMatches = []
            for matchedFileNameNode in node.getElementsByTagName('matchedFileName'):
                fileMatches.append(matchedFileNameNode.childNodes.item(0).nodeValue.strip())
            fileMatches = ' '.join(fileMatches)

            result.add_row([name, version, archs, repoURL, fileMatches]);

        return result

    @classmethod
    def main(cls, args=None):

        p = scout.Parser(cls.name)
        p.add_repos(['factory', 'suse110', 'suse103', 'suse102'])
        try:
            if not p.parse(args):
                return None
        except scout.HelpOptionFound:
            p.print_help()
            sys.exit(1)

        term = p.args[0]

        repos = p.get_repos()
        if repos == None:
            return None
        for repo in repos:
            dom = cls.query(term, repo)
            root = dom.getElementsByTagNameNS('http://datastructures.pkgsearch.benjiweber.co.uk', 'packages').item(0)
            return cls.fill_result(root)

        return None<commit_msg>Convert the webpin module to instance based and reimplements the BaseScoutModule class.<commit_after># Copyright (c) 2008 <NAME>
# see __init__.py for license details

import scout
import sys
import httplib
import urllib
from xml.dom import minidom

class ScoutModule(scout.BaseScoutModule):

    name = "webpin"
    desc = _("Search in packages using the webpin webservice.")
    distros = {
        'suse110' : 'openSUSE_110',
        'suse103' : 'openSUSE_103',
        'suse102' : 'openSUSE_102',
        'factory' : 'SUSE_Factory',
    }
    service_host = 'api.opensuse-community.org'
    service_baseurl = '/searchservice/Search/Simple/'

    def __init__(self):
        super(self.__class__, self).__init__()
        
        self._repo_list = scout.RepoList(self._cls.name, self._cls.distros.keys())
        self._parser    = scout.Parser(self._cls.name, self._repo_list.repos)

    def query(self, term, distro):
        cls = self.__class__
        try:
            url = cls.service_baseurl + cls.distros[distro] + '/' + urllib.quote(term)
            c = httplib.HTTPConnection(cls.service_host)
            c.connect()
            c.putrequest('GET', 'http://%s%s' % (cls.service_host, url))
            c.putheader('User-Agent', 'scout')
            c.putheader('Accept', 'text/xml')
            c.endheaders()
            r = c.getresponse()
            data = r.read()
            r.close()
            return minidom.parseString(data)
        except Exception, e:
            print _("Cannot retreive query results ... %s") % e
            return None

    def fill_result(self, root):
        scout.null_lang.install()
        result_list = [_("pkg"), _("ver"), _("arch"), _("repo"), _("files")]
        result_list2=[_("package"), _("version"), _("arch"), _("repository URL"), _("matched files")]
        scout.default_lang.install()
        result = scout.Result( result_list, result_list2 );

        for node in root.getElementsByTagName("package"):
            name = node.getElementsByTagName('name').item(0).childNodes.item(0).nodeValue
            version = node.getElementsByTagName('version').item(0).childNodes.item(0).nodeValue
            summary = node.getElementsByTagName('summary').item(0).childNodes.item(0).nodeValue
            repoURL = node.getElementsByTagName('repoURL').item(0).childNodes.item(0).nodeValue
            archs = []
            archsNode = node.getElementsByTagName('archs').item(0)
            if archsNode:
                for archNode in archsNode.getElementsByTagName('arch'):
                    archs.append(archNode.childNodes.item(0).nodeValue)
            archs = ' '.join(archs)
            fileMatches = []
            for matchedFileNameNode in node.getElementsByTagName('matchedFileName'):
                fileMatches.append(matchedFileNameNode.childNodes.item(0).nodeValue.strip())
            fileMatches = ' '.join(fileMatches)

            result.add_row([name, version, archs, repoURL, fileMatches]);

        return result

    def main(self, module_args=None):

        #p = scout.Parser(self._name)
        #p.add_repos(['factory', 'suse110', 'suse103', 'suse102'])
        args = None
        try:
            args = self._parser.parse_args(module_args)
        except scout.HelpOptionFound:
            p.print_help()
            sys.exit(1)

        term = args.query

        #repos = p.get_repos()
        repos = self._repo_list.repos
        if repos == None:
            return None
        for repo in repos:
            dom = self.query(term, repo)
            root = dom.getElementsByTagNameNS('http://datastructures.pkgsearch.benjiweber.co.uk', 'packages').item(0)
            return self.fill_result(root)

        return None
{'fraction_non_alphanumeric': 0.13006517427033154, 'fraction_numerical': 0.013176537262680647, 'mean_word_length': 2.318758815232722, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1405354', 'n_tokens_mistral': 2200, 'n_tokens_neox': 2096, 'n_words': 408}