<commit_before>from datetime import datetime, timedelta
from decimal import Decimal
import json
import uuid


from django.conf import settings
from django.db import models, connection
from django.utils import timezone


from prosodyauth import authenticate, managers
from prosodyauth.prosody.parsejid import nodeprep


# Create your models here.

def getProsodyDomain():
    return settings.PROSODY_DEFAULT_DOMAIN

class Prosody(models.Model):
    """
    Prosody model

    This model provides an interface for Django to access Prosody's database
    table. Each item in this table is indexed by Prosody via the tuple of
    (host,user,store,key). The type field describes the type of data that is
    stored in the value field, and can be one of:
      * string: String data
      * number: A (potentially) floating-point number
      * json: A JSON string
      * boolean: Simple true/false
    Note that this app assumes that Prosody is configured not to manage its own
    table; letting Prosody manage its table will very probably make it unusable
    in Django, and/or result in data loss.
    """

    host = models.TextField(default=getProsodyDomain)
    user = models.TextField(db_index=True)
    store = models.TextField(db_index=True)
    key = models.TextField(db_index=True)
    type = models.TextField(default='string')
    value = models.TextField()

    # Custom managers
    objects = managers.ProsodyQuerySet.as_manager()
    accounts = managers.ProsodyAccountsManager.from_queryset(managers.ProsodyQuerySet)()
    roster = managers.ProsodyRosterManager.from_queryset(managers.ProsodyQuerySet)()

    @property
    def decoded(self):
        if not self.type:
            raise AttributeError('Cannot decode value without a type')
        elif self.type == 'string':
            return self.value
        elif self.type == 'number':
            return Decimal(self.value)
        elif self.type == 'json':
            return json.loads(self.value)
        elif self.type == 'boolean':
            return self.type == "true"
        else:
            raise AttributeError('Unknown type definition: {}'.format(self.type))

    def encode(self, value):
        """Encode a native Python object into a string for Prosody's database.<commit_msg>Fix decoding of boolean values<commit_after>from datetime import datetime, timedelta
from decimal import Decimal
import json
import uuid


from django.conf import settings
from django.db import models, connection
from django.utils import timezone


from prosodyauth import authenticate, managers
from prosodyauth.prosody.parsejid import nodeprep


# Create your models here.

def getProsodyDomain():
    return settings.PROSODY_DEFAULT_DOMAIN

class Prosody(models.Model):
    """
    Prosody model

    This model provides an interface for Django to access Prosody's database
    table. Each item in this table is indexed by Prosody via the tuple of
    (host,user,store,key). The type field describes the type of data that is
    stored in the value field, and can be one of:
      * string: String data
      * number: A (potentially) floating-point number
      * json: A JSON string
      * boolean: Simple true/false
    Note that this app assumes that Prosody is configured not to manage its own
    table; letting Prosody manage its table will very probably make it unusable
    in Django, and/or result in data loss.
    """

    host = models.TextField(default=getProsodyDomain)
    user = models.TextField(db_index=True)
    store = models.TextField(db_index=True)
    key = models.TextField(db_index=True)
    type = models.TextField(default='string')
    value = models.TextField()

    # Custom managers
    objects = managers.ProsodyQuerySet.as_manager()
    accounts = managers.ProsodyAccountsManager.from_queryset(managers.ProsodyQuerySet)()
    roster = managers.ProsodyRosterManager.from_queryset(managers.ProsodyQuerySet)()

    @property
    def decoded(self):
        if not self.type:
            raise AttributeError('Cannot decode value without a type')
        elif self.type == 'string':
            return self.value
        elif self.type == 'number':
            return Decimal(self.value)
        elif self.type == 'json':
            return json.loads(self.value)
        elif self.type == 'boolean':
            return self.value == "true"
        else:
            raise AttributeError('Unknown type definition: {}'.format(self.type))

    def encode(self, value):
        """Encode a native Python object into a string for Prosody's database.
{'fraction_non_alphanumeric': 0.07671957671957672, 'fraction_numerical': 0.0, 'mean_word_length': 3.1970397779833486, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '1267098', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1191, 'n_words': 433}