Need help understanding some Python code

Posted by Yarin on Stack Overflow See other posts from Stack Overflow or by Yarin
Published on 2010-06-13T17:15:55Z Indexed on 2010/06/13 17:22 UTC
Read the original article Hit count: 223

Filed under:

I'm new to Python, and stumped by this piece of code from the Boto project:

class SubdomainCallingFormat(_CallingFormat):
    @assert_case_insensitive
    def get_bucket_server(self, server, bucket):
        return '%s.%s' % (bucket, server)

def assert_case_insensitive(f):
    def wrapper(*args, **kwargs):
        if len(args) == 3 and not (args[2].islower() or args[2].isalnum()):
            raise BotoClientError("Bucket names cannot contain upper-case " \
            "characters when using either the sub-domain or virtual " \
        "hosting calling format.")
        return f(*args, **kwargs)
    return wrapper

Trying to understand what's going on here.

  1. What is the '@' symbol in @assert_case_sensitive ?
  2. What do the args *args, **kwargs mean?
  3. What does 'f' represent?

Thanks!

© Stack Overflow or respective owner

Related posts about python