Skip to content

Commit

Permalink
Adding snaktype property.
Browse files Browse the repository at this point in the history
Claim object have now both properties:
* `snaktype`
* `value` set to `None` if `snaktype` is either `somevalue` or `novalue`
  • Loading branch information
PierreSelim committed Sep 6, 2015
1 parent a4aca5d commit 94edddb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions mwclient/entity.py
Expand Up @@ -171,7 +171,10 @@ class Claim(object):
Attributes:
prop (str): property id.
snak (dict): snak with all values return in mainsnak from API call.
snaktype (str): 'value', 'somevalue' or 'novalue'
datatype (str): datatype ('wikibase-item', 'string', etc.)
value (dict): content of snak['datavalue']['value'] if snaktype is
'value', None othewise.
string (str): string value, None if not 'string' datatype
item (Item): Item value, None if not 'wikibase-item' datatype
property_value (Property): Property, None if not 'wikibase-property'
Expand All @@ -181,12 +184,13 @@ class Claim(object):
quantity (dict): quantity dictionnary, None if not 'quantity' datatype
"""

def __init__(self, site, prop, datatype, value, snak=None):
def __init__(self, site, prop, datatype, snaktype, value=None, snak=None):
"""Constructor"""
self.site = site
self.prop = prop
self.datatype = datatype
self.value = value
self.snaktype = snaktype
self.snak = snak

@classmethod
Expand All @@ -197,9 +201,14 @@ def fromsnak(cls, site, snak):
site (mwclient.WikiBaseSite): site
snak (dict): snak dictionnary
"""
snakvalue = None
if snak['snaktype'] == 'value':
snakvalue = snak['datavalue']['value']
return cls(site, snak['property'],
snak['datatype'],
snak['datavalue']['value'])
snak['snaktype'],
value=snakvalue,
snak=snak)

def __repr__(self):
"""Representation."""
Expand Down

0 comments on commit 94edddb

Please sign in to comment.