<commit_before># Copyright 2015 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import random

from pushbaby.pushconnection import PushConnection, ConnectionDeadException
from pushbaby.feedbackconnection import FeedbackConnection


logger = logging.getLogger(__name__)


class PushBaby:
    """
    This class is all that you should need to use in the majority of cases.
    Sending a push can be achieved using the send() method.
    To receive errors, set the 'on_push_failed' member like so:

        def on_push_failed(token, identifier, status):
            [handle error]

        pb = PushBaby(cerfile='mycert.pem')
        pb.on_push_failed = on_push_failed
    """
    ADDRESSES = {
        'prod': ('gateway.push.apple.com', 2195),
        'sandbox': ('gateway.sandbox.push.apple.com', 2195)
    }
    FEEDBACK_ADDRESSES = {
        'prod': ('feedback.push.apple.com', 2196),
        'sandbox': ('feedback.sandbox.push.apple.com', 2196)
    }

    def __init__(self, certfile, keyfile=None, platform='sandbox', feedback_address=None):
        """
        Args:
            certfile: Path to a certificate file in PEM format
                      This may also include the private key.
            keyfile: Path to the private key file in PEM format
            platform: The platform to use ('sandbox' or 'prod')
                      or a tuple of hostname and port.
        """
        if isinstance(platform, str):
            if platform in PushBaby.ADDRESSES:
                self.address = PushBaby.ADDRESSES[platform]
                self.fbaddress = PushBaby.FEEDBACK_ADDRESSES[platform]
            else:
                self.address = (platform, 2195)
        else:
            self.address = platform

        if feedback_address:
            self.fbaddress = feedback_address

        if not self.fbaddress:
            logger.warn(
                "gateway address manually configured but no feedback_address " +
                "supplied. Fetching feedback will not work"
            )

        self.sock = None
        self.certfile = certfile<commit_msg>Oops: don't break if you don't supply a feedback address.<commit_after># Copyright 2015 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import random

from pushbaby.pushconnection import PushConnection, ConnectionDeadException
from pushbaby.feedbackconnection import FeedbackConnection


logger = logging.getLogger(__name__)


class PushBaby:
    """
    This class is all that you should need to use in the majority of cases.
    Sending a push can be achieved using the send() method.
    To receive errors, set the 'on_push_failed' member like so:

        def on_push_failed(token, identifier, status):
            [handle error]

        pb = PushBaby(cerfile='mycert.pem')
        pb.on_push_failed = on_push_failed
    """
    ADDRESSES = {
        'prod': ('gateway.push.apple.com', 2195),
        'sandbox': ('gateway.sandbox.push.apple.com', 2195)
    }
    FEEDBACK_ADDRESSES = {
        'prod': ('feedback.push.apple.com', 2196),
        'sandbox': ('feedback.sandbox.push.apple.com', 2196)
    }

    def __init__(self, certfile, keyfile=None, platform='sandbox', feedback_address=None):
        """
        Args:
            certfile: Path to a certificate file in PEM format
                      This may also include the private key.
            keyfile: Path to the private key file in PEM format
            platform: The platform to use ('sandbox' or 'prod')
                      or a tuple of hostname and port.
        """
        self.fbaddress = None
        if isinstance(platform, str):
            if platform in PushBaby.ADDRESSES:
                self.address = PushBaby.ADDRESSES[platform]
                self.fbaddress = PushBaby.FEEDBACK_ADDRESSES[platform]
            else:
                self.address = (platform, 2195)
        else:
            self.address = platform

        if feedback_address:
            self.fbaddress = feedback_address

        if not self.fbaddress:
            logger.warn(
                "gateway address manually configured but no feedback_address " +
                "supplied. Fetching feedback will not work"
            )

        self.sock = None
        self.certfile = certfile
{'fraction_non_alphanumeric': 0.07860922146636433, 'fraction_numerical': 0.010582010582010581, 'mean_word_length': 2.4347826086956523, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7517200', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1361, 'n_words': 508}