<commit_before>#
# Copyright (c) 2009 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.rpath.com/permanent/licenses/CPL-1.0.
#
# This program is distributed in the hope that it will be useful, but
# without any warranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#

from xobj import xobj
from conary import versions

class BaseObject(object):

    def __init__(self, **kwargs):
        for key, val in self.__class__.__dict__.iteritems():
            if type(val) == list:
                setattr(self, key, [])

        for key, val in kwargs.iteritems():
            if (hasattr(self.__class__, key) or
                (hasattr(self, '_xobj') and key in (self._xobj.attributes))):
                setattr(self, key, val)
            else:
                raise TypeError, 'unknown constructor parameter %s' % key

class BaseTroveInfo(BaseObject):

    name = str
    version = str
    flavor = str

    def __init__(self, version = None, mkUrl = None, **kwargs):
        BaseObject.__init__(self, version = version, **kwargs)
        if mkUrl:
            ver = versions.VersionFromString(version)
            host = ver.trailingLabel().getHost()
            self.id = mkUrl('trove', "%s=%s[%s]" % (self.name, self.version,
                                                    self.flavor),
                            host = host)

class TroveIdent(BaseTroveInfo):

    _xobj = xobj.XObjMetadata(attributes = { 'id' : str }, tag = 'trove')

class TroveIdentList(BaseObject):

    _xobj = xobj.XObjMetadata(tag = 'troveList')
    troveList = [ TroveIdent ]

    def append(self, name = None, version = None, flavor = None, mkUrl = None):
        self.troveList.append(TroveIdent(name = name, version = version,
                                         flavor = flavor, mkUrl = mkUrl))

class LabelList(BaseObject):

    _xobj = xobj.XObjMetadata(tag = 'LabelList')
    label = [ str ]

    def append(self, labelStr):
        self.label.append(labelStr)

class FileId(xobj.XObjStr):

    _xobj = xobj.XObjMetadata(attributes = { 'href' : str })

class FileInTrove(BaseObject):

    _xobj = xobj.XObjMetadata(attributes = { 'id' : str })

    path = str
    version = str
    fileId = str
    pathId = str

    def __init__(self, mkUrl = None, fileId = None, version = None,
                 thisHost = None, **kwargs):
        BaseObject.__init__(self, fileId = fileId, version = version, **kwargs)
        if mkUrl:
            host = versions.VersionFromString(version).trailingLabel().getHost()
            self.id = mkUrl('file', self.fileId, 'info', host = host)

class ReferencedTrove(BaseTroveInfo):
<commit_msg>xobjstr replaced by xobj class<commit_after>#
# Copyright (c) 2009 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.rpath.com/permanent/licenses/CPL-1.0.
#
# This program is distributed in the hope that it will be useful, but
# without any warranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#

from xobj import xobj
from conary import versions

class BaseObject(object):

    def __init__(self, **kwargs):
        for key, val in self.__class__.__dict__.iteritems():
            if type(val) == list:
                setattr(self, key, [])

        for key, val in kwargs.iteritems():
            if (hasattr(self.__class__, key) or
                (hasattr(self, '_xobj') and key in (self._xobj.attributes))):
                setattr(self, key, val)
            else:
                raise TypeError, 'unknown constructor parameter %s' % key

class BaseTroveInfo(BaseObject):

    name = str
    version = str
    flavor = str

    def __init__(self, version = None, mkUrl = None, **kwargs):
        BaseObject.__init__(self, version = version, **kwargs)
        if mkUrl:
            ver = versions.VersionFromString(version)
            host = ver.trailingLabel().getHost()
            self.id = mkUrl('trove', "%s=%s[%s]" % (self.name, self.version,
                                                    self.flavor),
                            host = host)

class TroveIdent(BaseTroveInfo):

    _xobj = xobj.XObjMetadata(attributes = { 'id' : str }, tag = 'trove')

class TroveIdentList(BaseObject):

    _xobj = xobj.XObjMetadata(tag = 'troveList')
    troveList = [ TroveIdent ]

    def append(self, name = None, version = None, flavor = None, mkUrl = None):
        self.troveList.append(TroveIdent(name = name, version = version,
                                         flavor = flavor, mkUrl = mkUrl))

class LabelList(BaseObject):

    _xobj = xobj.XObjMetadata(tag = 'LabelList')
    label = [ str ]

    def append(self, labelStr):
        self.label.append(labelStr)

class FileId(xobj.XObj):

    _xobj = xobj.XObjMetadata(attributes = { 'href' : str })

class FileInTrove(BaseObject):

    _xobj = xobj.XObjMetadata(attributes = { 'id' : str })

    path = str
    version = str
    fileId = str
    pathId = str

    def __init__(self, mkUrl = None, fileId = None, version = None,
                 thisHost = None, **kwargs):
        BaseObject.__init__(self, fileId = fileId, version = version, **kwargs)
        if mkUrl:
            host = versions.VersionFromString(version).trailingLabel().getHost()
            self.id = mkUrl('file', self.fileId, 'info', host = host)

class ReferencedTrove(BaseTroveInfo):

{'fraction_non_alphanumeric': 0.10761421319796954, 'fraction_numerical': 0.0027072758037225042, 'mean_word_length': 2.4997039668442866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4395429', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1694, 'n_words': 528}