<commit_before>#
# Base class for all SfaAPI functions
#
#

import time
from types import IntType, LongType, StringTypes
import textwrap

from sfa.util.sfalogging import logger
from sfa.util.faults import SfaFault, SfaInvalidAPIMethod, SfaInvalidArgumentCount, SfaInvalidArgument

from sfa.storage.parameter import Parameter, Mixed, python_type, xmlrpc_type

class Method:
    """
    Base class for all SfaAPI functions. At a minimum, all SfaAPI
    functions must define:

    interfaces = [allowed interfaces]
    accepts = [Parameter(arg1_type, arg1_doc), Parameter(arg2_type, arg2_doc), ...]
    returns = Parameter(return_type, return_doc)
    call(arg1, arg2, ...): method body

    Argument types may be Python types (e.g., int, bool, etc.), typed
    values (e.g., 1, True, etc.), a Parameter, or lists or
    dictionaries of possibly mixed types, values, and/or Parameters
    (e.g., [int, bool, ...]  or {'arg1': int, 'arg2': bool}).

    Once function decorators in Python 2.4 are fully supported,
    consider wrapping calls with accepts() and returns() functions
    instead of performing type checking manually.
    """

    interfaces = []
    accepts = []
    returns = bool
    status = "current"

    def call(self, *args):
        """
        Method body for all SfaAPI functions. Must override.
        """
        return None

    def __init__(self, api):
        self.name = self.__class__.__name__
        self.api = api

        # Auth may set this to a Person instance (if an anonymous
        # method, will remain None).
        self.caller = None

        # API may set this to a (addr, port) tuple if known
        self.source = None
    	
    def __call__(self, *args, **kwds):
        """
        Main entry point for all SfaAPI functions. Type checks
        arguments, authenticates, and executes call().
        """

        try:
            start = time.time()
            methodname = self.name
            if not self.api.interface or self.api.interface not in self.interfaces:
                raise SfaInvalidAPIMethod(methodname, self.api.interface) 

            (min_args, max_args, defaults) = self.args()
	    		
            # Check that the right number of arguments were passed in
            if len(args) < len(min_args) or len(args) > len(max_args):
                raise SfaInvalidArgumentCount(len(args), len(min_args), len(max_args))

            for name, value, expected in zip(max_args, args, self.accepts):
                self.type_check(name, value, expected, args)

            logger.debug("method.__call__ [%s] : BEG %s"%(self.api.interface,methodname))
            result = self.call(*args, **kwds)
<commit_msg>cosmetic<commit_after>#
# Base class for all SfaAPI functions
#
#

import time
from types import IntType, LongType, StringTypes
import textwrap

from sfa.util.sfalogging import logger
from sfa.util.faults import SfaFault, SfaInvalidAPIMethod, SfaInvalidArgumentCount, SfaInvalidArgument

from sfa.storage.parameter import Parameter, Mixed, python_type, xmlrpc_type

class Method:
    """
    Base class for all SfaAPI functions. At a minimum, all SfaAPI
    functions must define:

    interfaces = [allowed interfaces]
    accepts = [Parameter(arg1_type, arg1_doc), Parameter(arg2_type, arg2_doc), ...]
    returns = Parameter(return_type, return_doc)
    call(arg1, arg2, ...): method body

    Argument types may be Python types (e.g., int, bool, etc.), typed
    values (e.g., 1, True, etc.), a Parameter, or lists or
    dictionaries of possibly mixed types, values, and/or Parameters
    (e.g., [int, bool, ...]  or {'arg1': int, 'arg2': bool}).

    Once function decorators in Python 2.4 are fully supported,
    consider wrapping calls with accepts() and returns() functions
    instead of performing type checking manually.
    """

    interfaces = []
    accepts = []
    returns = bool
    status = "current"

    def call(self, *args):
        """
        Method body for all SfaAPI functions. Must override.
        """
        return None

    def __init__(self, api):
        self.name = self.__class__.__name__
        self.api = api

        # Auth may set this to a Person instance (if an anonymous
        # method, will remain None).
        self.caller = None

        # API may set this to a (addr, port) tuple if known
        self.source = None
    	
    def __call__(self, *args, **kwds):
        """
        Main entry point for all SFA API functions. Type checks
        arguments, authenticates, and executes call().
        """

        try:
            start = time.time()
            methodname = self.name
            if not self.api.interface or self.api.interface not in self.interfaces:
                raise SfaInvalidAPIMethod(methodname, self.api.interface) 

            (min_args, max_args, defaults) = self.args()
	    		
            # Check that the right number of arguments were passed in
            if len(args) < len(min_args) or len(args) > len(max_args):
                raise SfaInvalidArgumentCount(len(args), len(min_args), len(max_args))

            for name, value, expected in zip(max_args, args, self.accepts):
                self.type_check(name, value, expected, args)

            logger.debug("method.__call__ [%s] : BEG %s"%(self.api.interface,methodname))
            result = self.call(*args, **kwds)

{'fraction_non_alphanumeric': 0.09925093632958802, 'fraction_numerical': 0.004119850187265918, 'mean_word_length': 2.5324074074074074, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '7204655', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1516, 'n_words': 519}