Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6969

Determine attributes of calling method

From Joe <joe.cwikla@gmail.com>
Newsgroups comp.lang.python
Subject Determine attributes of calling method
Date 2011-06-03 13:35 -0700
Organization http://groups.google.com
Message-ID <6708872e-bf6e-4f7c-b9ec-d00a71cddc4f@j23g2000yqc.googlegroups.com> (permalink)

Show all headers | View raw


Hello,

I'm trying to implement a way to restrict method usage based on the
caller's attributes.  In the following example I'd like to execute the
server method "bar" only if the caller's method has a "blue" value for
it's color attribute.

The current output is:

blue
red
bar
bar

I'd like it to be:

blue
red
bar

I've worked my way through inspect but that doesn't seem to be the
right approach.

# Example
class Client:

    def __init__(self, server):
        self.server=server

    def foo(self):
        self.server.bar()

    def fu(self):
        self.server.bar()

    foo.__dict__['color']='blue'
    fu.__dict__['color']='red'

class BlueServer:

    def bar(self):
        """
        Goal is to only accept calls from "blue" client methods.
        Don't know how to do it :(
        """
        print "bar"

s=BlueServer()
c=Client(s)
print c.foo.color
print c.fu.color
c.foo()
c.fu()

Thanks for your help!

Joe

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Determine attributes of calling method Joe <joe.cwikla@gmail.com> - 2011-06-03 13:35 -0700
  Re: Determine attributes of calling method Richard Thomas <chardster@gmail.com> - 2011-06-04 04:54 -0700
  Re: Determine attributes of calling method Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-04 14:02 -0600

csiph-web