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 4405c21
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mwclient/entity.py
Expand Up @@ -181,12 +181,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 +198,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 4405c21

Please sign in to comment.