Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8583693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:35:55+00:00 2026-06-11T21:35:55+00:00

class SignedFileRequest(SignedRequest): def __init__(self, host, path, node_id = None, name=None, \ content_type=None, hash=None, ssl=False,

  • 0
class SignedFileRequest(SignedRequest):
    def __init__(self, host, path, node_id = None, name=None, \
                 content_type=None, hash=None, ssl=False, expires=0):
        super(SignedFileRequest, self).__init__(host, path, ssl, expires)
        self.name = name
        self.content_type = content_type
        self.hash = hash
        self.node_id = node_id
    def get_name(self):
        return self.query_dict.get(NAME_KEY)
    def set_name(self, value):
        self.query_dict[NAME_KEY] = value
    def get_content_type(self):
        return self.query_dict.get(CONTENT_TYPE_KEY)
    def set_content_type(self, value):
        self.query_dict[CONTENT_TYPE_KEY] = value
    def get_hash(self):
        return self.query_dict.get(HASH_KEY)
    def set_hash(self, value):
        self.query_dict[HASH_KEY] = value
    def get_node_id(self):
        return self.query_dict.get(NODE_ID_KEY)
    def set_node_id(self, value):
        self.query_dict[NODE_ID_KEY] = value
    name = property(get_name, set_name)
    content_type = property(get_content_type, set_content_type)
    hash = property(get_hash, set_hash)
    node_id = property(get_node_id, set_node_id)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:35:56+00:00Added an answer on June 11, 2026 at 9:35 pm

    You could use the __getattr__ and __setattr__ hooks instead of a meta class:

    class SignedFileRequest(SignedRequest):
        __attr_map = dict(name=NAME_KEY, content_type=CONTENT_TYPE_KEY,
                          hash=HASH_KEY, node_id=NODE_ID_KEY)
    
        def __init__(self, host, path, node_id = None, name=None, \
                     content_type=None, hash=None, ssl=False, expires=0):
            super(SignedFileRequest, self).__init__(host, path, ssl, expires)
            self.name = name
            self.content_type = content_type
            self.hash = hash
            self.node_id = node_id
    
        def __getattr__(self, attr):
            if attr in self.__attr_map:
                return self.query_dict.get(self.__attr_map[attr])
            return super(SignedFileRequest, self).__getattr__(attr)
    
        def __setattr__(self, attr, value):
            if attr in self.__attr_map:
                self.query_dict[self.__attr_map[attr]] = value
            super(SignedFileRequest, self).__setattr__(attr, value)
    

    Alternatively, the same mapping can be used to create a class decorator:

    def add_property(klass, name, key):
        def getter(self):
            return self.query_dict.get(key)
        def setter(self, value):
            self.query_dict[key] = value
        setattr(klass, name, property(getter, setter))
    
    def set_properties(**mapping):
        def decorator(klass):
            for name, key in mapping.iteritems():
                add_property(klass, name, key)
            return klass
        return decorator
    
    @set_properties(name=NAME_KEY, content_type=CONTENT_TYPE_KEY,
                    hash=HASH_KEY, node_id=NODE_ID_KEY)
    class SignedFileRequest(SignedRequest):
        def __init__(self, host, path, node_id = None, name=None, \
                     content_type=None, hash=None, ssl=False, expires=0):
            super(SignedFileRequest, self).__init__(host, path, ssl, expires)
            self.name = name
            self.content_type = content_type
            self.hash = hash
            self.node_id = node_id
    

    Or you could go with a meta class approach anyway:

     def mapped_properties_meta(**mapping):
         def mapped_meta(name, bases, attrs):
             klass = type(name, bases, attrs)
             for name, key in mapping.iteritems():
                 add_property(klass, name, key)
             return klass
         return mapped_meta
    
    
    class SignedFileRequest(SignedRequest):
        __metaclass__ = mapped_properties_meta(
           name=NAME_KEY, content_type=CONTENT_TYPE_KEY,
           hash=HASH_KEY, node_id=NODE_ID_KEY)
    
        def __init__(self, host, path, node_id = None, name=None, \
                     content_type=None, hash=None, ssl=False, expires=0):
            super(SignedFileRequest, self).__init__(host, path, ssl, expires)
            self.name = name
            self.content_type = content_type
            self.hash = hash
            self.node_id = node_id
    

    The latter reuses the add_property function from the decorator approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class MyClass(Object): def __init__(self, x=None): if x: self.x = x def do_something(self): print self.x
class StartAction(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): print "Hello" start.add_argument('-s', '--start', action=StartAction) I
class MyClass(object): def __init__(self): self._my_secret_thing = 1 def _i_get(self): return self._my_secret_thing def _i_set(self, value):
class ShortInputException(Exception): '''A user-defined exception class.''' def __init__(self, length, atleast): Exception.__init__(self) self.length = length
class test: def __init__(self, val): self.val = val self.val.lower() Why doesn't lower() operate on
class myClass (models.Model): related_operation = models.ForeignKey('self', null = True) __related_operation = None def save(self,
class A: pass def b(self): print('b') A.b = b a = A() At this
class Book(models.Model): name = models.CharField(max_length=127, blank=False) class Author(models.Model): name = models.CharField(max_length=127, blank=False) books =
class ITestType(object): Sample interface type __metaclass__ = ABCMeta @abstractmethod def requiredCall(self): return class TestType1(object):
class Anketum < ActiveRecord::Base has_one :user class << self def search(params) self.scope :h, :conditions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.