<commit_before>#
# error.py
# CloudKitPy
#
# Created by <NAME> on 01/05/2016.
# Copyright (c) 2016 <NAME> - Pig on a Hill Productions.
#

# !/usr/bin/env python

from datatypes import ZoneID
from helpers import parse


class CKError:

    is_error = False
    ck_error_code = None
    is_server_error = False
    server_error_code = None
    reason = None
    retry_after = None
    uuid = None
    redirect_url = None
    record_name = None
    subscription_id = None
    zone_id = None
    payload = None

    def __init__(self, json, payload):
        self.ck_error_code = parse(json, 'ckErrorCode')
        self.is_error = self.ck_error_code is not None
        self.server_error_code = parse(json, 'serverErrorCode')
        self.is_server_error = self.server_error_code is not None
        self.reason = parse(json, 'reason')
        self.retry_after = parse(json, 'retryAfter')
        self.uuid = parse(json, 'uuid')
        self.redirect_url = parse(json, 'redirectURL')
        self.record_name = parse(json, 'recordName')
        self.subscription_id = parse(json, 'subscriptionID')
        zone_id_json = parse(json, 'zoneID')
        if zone_id_json is not None:
            zone_id = ZoneID(zone_id_json)
            self.zone_id = zone_id
        self.payload = payload

    ACCESS_DENIED = 'ACCESS_DENIED'
    ATOMIC_ERROR = 'ATOMIC_ERROR'
    AUTHENTICATION_FAILED = 'AUTHENTICATION_FAILED'
    AUTHENTICATION_REQUIRED = 'AUTHENTICATION_REQUIRED'
    BAD_REQUEST = 'BAD_REQUEST'
    CONFLICT = 'CONFLICT'
    EXISTS = 'EXISTS'
    INTERNAL_ERROR = 'INTERNAL_ERROR'
    NOT_FOUND = 'NOT_FOUND'
    QUOTA_EXCEEDED = 'QUOTA_EXCEEDED'
    SIGN_IN_FAILED = 'SIGN_IN_FAILED'
    THROTTLED = 'THROTTLED'
    TRY_AGAIN_LATER = 'TRY_AGAIN_LATER'
    VALIDATING_REFERENCE_ERROR = 'VALIDATING_REFERENCE_ERROR'
    UNIQUE_FIELD_ERROR = 'UNIQUE_FIELD_ERROR'
    ZONE_NOT_FOUND = 'ZONE_NOT_FOUND'<commit_msg>Fixed crash when creating an CKError if json is None.<commit_after>#
# error.py
# CloudKitPy
#
# Created by <NAME> on 01/05/2016.
# Copyright (c) 2016 <NAME> - Pig on a Hill Productions.
#

# !/usr/bin/env python

from datatypes import ZoneID
from helpers import parse


class CKError:

    is_error = False
    ck_error_code = None
    is_server_error = False
    server_error_code = None
    reason = None
    retry_after = None
    uuid = None
    redirect_url = None
    record_name = None
    subscription_id = None
    zone_id = None
    payload = None

    def __init__(self, json, code, payload):
        if json is not None:
            self.ck_error_code = parse(json, 'ckErrorCode')
            self.is_error = self.ck_error_code is not None
            self.server_error_code = parse(json, 'serverErrorCode')
            self.is_server_error = self.server_error_code is not None
            self.reason = parse(json, 'reason')
            self.retry_after = parse(json, 'retryAfter')
            self.uuid = parse(json, 'uuid')
            self.redirect_url = parse(json, 'redirectURL')
            self.record_name = parse(json, 'recordName')
            self.subscription_id = parse(json, 'subscriptionID')
            zone_id_json = parse(json, 'zoneID')
            if zone_id_json is not None:
                zone_id = ZoneID(zone_id_json)
                self.zone_id = zone_id
        self.payload = payload

    ACCESS_DENIED = 'ACCESS_DENIED'
    ATOMIC_ERROR = 'ATOMIC_ERROR'
    AUTHENTICATION_FAILED = 'AUTHENTICATION_FAILED'
    AUTHENTICATION_REQUIRED = 'AUTHENTICATION_REQUIRED'
    BAD_REQUEST = 'BAD_REQUEST'
    CONFLICT = 'CONFLICT'
    EXISTS = 'EXISTS'
    INTERNAL_ERROR = 'INTERNAL_ERROR'
    NOT_FOUND = 'NOT_FOUND'
    QUOTA_EXCEEDED = 'QUOTA_EXCEEDED'
    SIGN_IN_FAILED = 'SIGN_IN_FAILED'
    THROTTLED = 'THROTTLED'
    TRY_AGAIN_LATER = 'TRY_AGAIN_LATER'
    VALIDATING_REFERENCE_ERROR = 'VALIDATING_REFERENCE_ERROR'
    UNIQUE_FIELD_ERROR = 'UNIQUE_FIELD_ERROR'
    ZONE_NOT_FOUND = 'ZONE_NOT_FOUND'
{'fraction_non_alphanumeric': 0.0862635972678978, 'fraction_numerical': 0.006071338224133569, 'mean_word_length': 2.95004995004995, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5352577', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1356, 'n_words': 288}