<commit_before>#
# Copyright (c) 2004-2006 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.opensource.org/licenses/cpl.php.
#
# This program is distributed in the hope that it will be useful, but
# without any waranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#

import base64
import gzip
import httplib
import itertools
import os
import socket
import sys
import urllib
import xml
import xmlrpclib

#conary
from conary import callbacks
from conary import conarycfg
from conary import files
from conary import metadata
from conary import trove
from conary import versions
from conary.lib import util
from conary.repository import changeset
from conary.repository import errors
from conary.repository import filecontents
from conary.repository import findtrove
from conary.repository import repository
from conary.repository import transport
from conary.repository import trovesource
from conary.repository import xmlshims

# FIXME: remove these compatibility exception classes later
AlreadySignedError = errors.AlreadySignedError
FileStreamNotFound = errors.FileStreamNotFound
UserNotFound = errors.UserNotFound
GroupAlreadyExists = errors.GroupAlreadyExists
PermissionAlreadyExists = errors.PermissionAlreadyExists

shims = xmlshims.NetworkConvertors()

CLIENT_VERSIONS = [ 36, 37 ]

# this is a quote function that quotes all RFC 2396 reserved characters,
# including / (which is normally considered "safe" by urllib.quote)
quote = lambda s: urllib.quote(s, safe='')

class _Method(xmlrpclib._Method, xmlshims.NetworkConvertors):

    def __init__(self, send, name, host, pwCallback, anonymousCallback,
                 altHostCallback):
        xmlrpclib._Method.__init__(self, send, name)
        self.__host = host
        self.__pwCallback = pwCallback
        self.__anonymousCallback = anonymousCallback
        self.__altHostCallback = altHostCallback

    def __repr__(self):
        return "<netclient._Method(%s, %r)>" % (self._Method__send, self._Method__name) 

    def __str__(self):
        return self.__repr__()

    def __call__(self, *args):
        return self.doCall(CLIENT_VERSIONS[-1], *args)

    def __doCall(self, clientVersion, argList):
        newArgs = ( clientVersion, ) + argList

        try:
            usedAnonymous, isException, result = self.__send(self.__name,
                                                             newArgs)
        except xmlrpclib.ProtocolError, e:
            if e.errcode == 403:
                raise errors.InsufficientPermission(e.url.split("/")[2])
            raise
        if usedAnonymous:
            self.__anonymousCallback()

	if not isException:
	    return result
        else:
            self.handleError(result)

    def doCall(self, clientVersion, *args):
        try:
            return self.__doCall(clientVersion, args)
        except errors.InsufficientPermission:
            # no password was specified -- prompt for it
            if not self.__pwCallback():
                # It's possible we switched to anonymous
                # for an earlier query, and now need to 
                # switch back to our specified user/passwd
                if self.__altHostCallback():
                    self.__altHostCallback = None
                    # recursively call doCall to get all the 
                    # password handling goodness
                    return self.doCall(clientVersion, *args)
                raise
        except xmlrpclib.ProtocolError, err:
            if err.errcode == 500:
                raise errors.InternalServerError(err)
            raise
        except:
            raise

        return self.__doCall(clientVersion, args)

    def handleError(self, result):
	exceptionName = result[0]
	exceptionArgs = result[1:]

	if exceptionName == "TroveMissing":
	    (name, version) = exceptionArgs
	    if not name: name = None
	    if not version:
		version = None<commit_msg>check to make sure we haven't unset callback before calling<commit_after>#
# Copyright (c) 2004-2006 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.opensource.org/licenses/cpl.php.
#
# This program is distributed in the hope that it will be useful, but
# without any waranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#

import base64
import gzip
import httplib
import itertools
import os
import socket
import sys
import urllib
import xml
import xmlrpclib

#conary
from conary import callbacks
from conary import conarycfg
from conary import files
from conary import metadata
from conary import trove
from conary import versions
from conary.lib import util
from conary.repository import changeset
from conary.repository import errors
from conary.repository import filecontents
from conary.repository import findtrove
from conary.repository import repository
from conary.repository import transport
from conary.repository import trovesource
from conary.repository import xmlshims

# FIXME: remove these compatibility exception classes later
AlreadySignedError = errors.AlreadySignedError
FileStreamNotFound = errors.FileStreamNotFound
UserNotFound = errors.UserNotFound
GroupAlreadyExists = errors.GroupAlreadyExists
PermissionAlreadyExists = errors.PermissionAlreadyExists

shims = xmlshims.NetworkConvertors()

CLIENT_VERSIONS = [ 36, 37 ]

# this is a quote function that quotes all RFC 2396 reserved characters,
# including / (which is normally considered "safe" by urllib.quote)
quote = lambda s: urllib.quote(s, safe='')

class _Method(xmlrpclib._Method, xmlshims.NetworkConvertors):

    def __init__(self, send, name, host, pwCallback, anonymousCallback,
                 altHostCallback):
        xmlrpclib._Method.__init__(self, send, name)
        self.__host = host
        self.__pwCallback = pwCallback
        self.__anonymousCallback = anonymousCallback
        self.__altHostCallback = altHostCallback

    def __repr__(self):
        return "<netclient._Method(%s, %r)>" % (self._Method__send, self._Method__name) 

    def __str__(self):
        return self.__repr__()

    def __call__(self, *args):
        return self.doCall(CLIENT_VERSIONS[-1], *args)

    def __doCall(self, clientVersion, argList):
        newArgs = ( clientVersion, ) + argList

        try:
            usedAnonymous, isException, result = self.__send(self.__name,
                                                             newArgs)
        except xmlrpclib.ProtocolError, e:
            if e.errcode == 403:
                raise errors.InsufficientPermission(e.url.split("/")[2])
            raise
        if usedAnonymous:
            self.__anonymousCallback()

	if not isException:
	    return result
        else:
            self.handleError(result)

    def doCall(self, clientVersion, *args):
        try:
            return self.__doCall(clientVersion, args)
        except errors.InsufficientPermission:
            # no password was specified -- prompt for it
            if not self.__pwCallback():
                # It's possible we switched to anonymous
                # for an earlier query, and now need to 
                # switch back to our specified user/passwd
                if self.__altHostCallback and self.__altHostCallback():
                    self.__altHostCallback = None
                    # recursively call doCall to get all the 
                    # password handling goodness
                    return self.doCall(clientVersion, *args)
                raise
        except xmlrpclib.ProtocolError, err:
            if err.errcode == 500:
                raise errors.InternalServerError(err)
            raise
        except:
            raise

        return self.__doCall(clientVersion, args)

    def handleError(self, result):
	exceptionName = result[0]
	exceptionArgs = result[1:]

	if exceptionName == "TroveMissing":
	    (name, version) = exceptionArgs
	    if not name: name = None
	    if not version:
		version = None
{'fraction_non_alphanumeric': 0.0657354149548069, 'fraction_numerical': 0.007043080173729311, 'mean_word_length': 2.7715803452855248, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 18}, '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': '642117', 'n_tokens_mistral': 2260, 'n_tokens_neox': 2137, 'n_words': 772}