<commit_before>from django.conf import settings
import traceback
import logging
import sys
from restclients.pws import PWS
from myuw_mobile.user import UserService
from myuw_mobile.logger.timer import Timer

pws = PWS()

class Person:
    """
    The Person class encapsulates the interactions
    with the PWS person resource
    """

    # static class variables
    _logger = logging.getLogger('myuw_mobile.dao.pws.Person')

    def __init__(self, user_service):
        self._user_service = user_service
        self._netid = user_service.get_user()

    def get_person_by_netid(self):
        timer = Timer()
        try:
            return pws.get_person_by_netid(self._netid)
        except Exception, message:
            print 'Failed to get person data: ', message
            traceback.print_exc()
            Person._logger.error("get_person_by_netid %s %s", 
                                 Exception, message,
                                 self._user_service.get_log_user_info())
        finally:
            Person._logger.info("PWS get_person_by_netid time=%s", 
                                timer.get_elapsed(),
                                self._user_service.get_log_user_info())
        return None

    def is_student(self):
        return self.get_person_by_netid().is_student

    def get_regid(self):
        return self.get_person_by_netid().uwregid

    def get_contact(self, regid):
        contact = None
        timer = Timer()
        try:
            contact = pws.get_contact(regid)
        except Exception, message:
            print 'Failed to get instructor data: ', message
            traceback.print_exc()
            Person._logger.error("get_contact for %s: %s %s", 
                                 regid, Exception, message,
                                 self._user_service.get_log_user_info())
        finally:
            Person._logger.info("PWS get_contact for %s time=%s", 
                                regid, timer.get_elapsed(),
                                self._user_service.get_log_user_info())

        if contact and not contact["WhitepagesPublish"] :
            affiliations = contact["PersonAffiliations"]
            if "EmployeePersonAffiliation" in affiliations:
                data = affiliations["EmployeePersonAffiliation"]
                data["EmployeeWhitePages"] = {}

            if "StudentPersonAffiliation" in affiliations:
                data = affiliations["StudentPersonAffiliation"]
                data["StudentWhitePages"] = {}

        return contact                


<commit_msg>Added a validation in the is_student and get_regid methods..<commit_after>from django.conf import settings
import traceback
import logging
import sys
from restclients.pws import PWS
from myuw_mobile.user import UserService
from myuw_mobile.logger.timer import Timer

pws = PWS()

class Person:
    """
    The Person class encapsulates the interactions
    with the PWS person resource
    """

    # static class variables
    _logger = logging.getLogger('myuw_mobile.dao.pws.Person')

    def __init__(self, user_service):
        self._user_service = user_service
        self._netid = user_service.get_user()
        
    def get_person_by_netid(self):
        timer = Timer()
        try:
            return pws.get_person_by_netid(self._netid)
        except Exception, message:
            print 'Failed to get person data: ', message
            traceback.print_exc()
            Person._logger.error("get_person_by_netid %s %s", 
                                 Exception, message,
                                 self._user_service.get_log_user_info())
        finally:
            Person._logger.info("PWS get_person_by_netid time=%s", 
                                timer.get_elapsed(),
                                self._user_service.get_log_user_info())
        return None

    def is_student(self):
        res = self.get_person_by_netid()
        if res:
            return res.is_student
        return None

    def get_regid(self):
        res = self.get_person_by_netid()
        if res:
            return res.uwregid
        return None

    def get_contact(self, regid):
        contact = None
        timer = Timer()
        try:
            contact = pws.get_contact(regid)
        except Exception, message:
            print 'Failed to get instructor data: ', message
            traceback.print_exc()
            Person._logger.error("get_contact for %s: %s %s", 
                                 regid, Exception, message,
                                 self._user_service.get_log_user_info())
        finally:
            Person._logger.info("PWS get_contact for %s time=%s", 
                                regid, timer.get_elapsed(),
                                self._user_service.get_log_user_info())

        if contact and not contact["WhitepagesPublish"] :
            affiliations = contact["PersonAffiliations"]
            if "EmployeePersonAffiliation" in affiliations:
                data = affiliations["EmployeePersonAffiliation"]
                data["EmployeeWhitePages"] = {}

            if "StudentPersonAffiliation" in affiliations:
                data = affiliations["StudentPersonAffiliation"]
                data["StudentWhitePages"] = {}

        return contact                



{'fraction_non_alphanumeric': 0.07840930407053086, 'fraction_numerical': 0.0, 'mean_word_length': 1.834662413609782, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3477425', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1367, 'n_words': 322}