<commit_before>import collections
import sys
import urllib.parse

from wordpress_xmlrpc.compat import xmlrpc_client, dict_type
from wordpress_xmlrpc.exceptions import ServerConnectionError, UnsupportedXmlrpcMethodError, InvalidCredentialsError, XmlrpcDisabledError


class Client(object):

    """
    Connection to a WordPress XML-RPC API endpoint.

    To execute XML-RPC methods, pass an instance of an
    `XmlrpcMethod`-derived class to `Client`'s `call` method.
    """

    def __init__(self, url, username, password, blog_id=0, transport=None, verbose=False, safe_transport=None):
        self.url = url
        self.username = username
        self.password = password
        self.blog_id = blog_id

        self.setup(transport, verbose, safe_transport)

    def setup(self, transport, verbose, safe_transport):
        try:
            self.server = xmlrpc_client.ServerProxy(self.url, allow_none=True, transport=transport,
                                                    verbose=verbose)
            self.supported_methods = self.server.mt.supportedMethods()
        except xmlrpc_client.ProtocolError:
            e = sys.exc_info()[1]
            if e.errcode == 301:
                try:
                    self.url = e.headers['location']
                except KeyError:
                    self.url = e.headers['Location']

                protocol, _ = urllib.parse.splittype(self.url)
                if protocol == 'https':
                    transport = safe_transport

                self.setup(transport, verbose, None)
            else:
                raise ServerConnectionError(repr(e))

    def call(self, method):
        if method.method_name not in self.supported_methods:
            raise UnsupportedXmlrpcMethodError(method.method_name)

        server_method = getattr(self.server, method.method_name)
        args = method.get_args(self)
<commit_msg>When error code is 302 force to user safe transport<commit_after>import collections
import sys
import urllib.parse

from wordpress_xmlrpc.compat import xmlrpc_client, dict_type
from wordpress_xmlrpc.exceptions import ServerConnectionError, UnsupportedXmlrpcMethodError, InvalidCredentialsError, XmlrpcDisabledError


class Client(object):

    """
    Connection to a WordPress XML-RPC API endpoint.

    To execute XML-RPC methods, pass an instance of an
    `XmlrpcMethod`-derived class to `Client`'s `call` method.
    """

    def __init__(self, url, username, password, blog_id=0, transport=None, verbose=False, safe_transport=None):
        self.url = url
        self.username = username
        self.password = password
        self.blog_id = blog_id

        self.setup(transport, verbose, safe_transport)

    def setup(self, transport, verbose, safe_transport):
        try:
            self.server = xmlrpc_client.ServerProxy(self.url, allow_none=True, transport=transport,
                                                    verbose=verbose)
            self.supported_methods = self.server.mt.supportedMethods()
        except xmlrpc_client.ProtocolError:
            e = sys.exc_info()[1]
            if e.errcode in [301, 302]:
                try:
                    self.url = e.headers['location']
                except KeyError:
                    self.url = e.headers['Location']

                protocol, _ = urllib.parse.splittype(self.url)
                if protocol == 'https':
                    transport = safe_transport

                self.setup(transport, verbose, None)
            else:
                raise ServerConnectionError(repr(e))

    def call(self, method):
        if method.method_name not in self.supported_methods:
            raise UnsupportedXmlrpcMethodError(method.method_name)

        server_method = getattr(self.server, method.method_name)
        args = method.get_args(self)

{'fraction_non_alphanumeric': 0.08161668839634942, 'fraction_numerical': 0.0041720990873533245, 'mean_word_length': 2.2983662940670677, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1428132', 'n_tokens_mistral': 1038, 'n_tokens_neox': 974, 'n_words': 245}