1
2
3
4
5
6
7
8
9
10
11 from util import Util
12 try:
13 from mcuser import MCUser
14 except ImportError:
15 pass
19
20 - def __init__(self, domainName, taskPath, *args, **kw):
30
33
36
39
42
45
46 - def setDomain(self, domain):
47 '''
48 Sets the domain for this request
49
50 @param domain: A C{Domain} object
51 '''
52 self._domain = Util.dumps(domain)
53
55 '''
56 Returns the domain for this request
57
58 @returns: The domain for this request
59 '''
60 return Util.loads(self._domain)
61
62 - def domainName(self):
63 '''
64 Returns the domain name for this request
65
66 @returns: The domain name for this request
67 '''
68 return Util.loads(self._domainName)
69
70 - def setDomainName(self, domainName):
71 '''
72 Sets the domain name
73
74 @param domainName: Domain name for this request
75 @type domainName: str
76 '''
77 self._domainName = Util.dumps(domainName)
78
80 '''
81 Sets the user object for this client request.
82 '''
83 self._user = user
84 self._userConvertedToDict = False
85
87 '''
88 Sets the user object as an dict for this client request.
89 Since user objects are unpickable, this method is used
90 to pickle ClientRequest and send it to remote peers.
91
92 @param userDict: A dict, previously obtained from User.toDict()
93 '''
94 self._user = Util.dumps(userDict)
95 self._userConvertedToDict = True
96
98 '''
99 Returns the user object for this request. Automatically
100 converts dict format to normal user object if this is the
101 case.
102
103 @returns: An C{MCUser} instance
104 '''
105 if self._userConvertedToDict:
106 user = MCUser.fromDict(Util.loads(self._user))
107 user.setVirtual(True)
108 return user
109 else:
110 return self._user
111
113 '''
114 Convert this instance to a (pickled) string.
115 '''
116 retval = {
117 '_domainName': self._domainName,
118 '_taskPath': self._taskPath,
119 '_args': self._args,
120 '_kw': self._kw,
121 '_domain': self._domain,
122 }
123
124 user = self.user()
125
126 if user is not None:
127 retval['_userDict'] = user.toDict()
128
129 return Util.dumps(retval)
130
131 @staticmethod
133 '''
134 Create a new instance from the passed pickled string.
135
136 @param aStr: A str, previously obtained from ClientRequest.dumps()
137 '''
138 crDict = Util.loads(aStr)
139
140 cr = ClientRequest(None, None)
141 for attr in ['_domainName', '_taskPath', '_args', '_kw', '_domain']:
142 setattr(cr, attr, crDict[attr])
143
144 try:
145 cr.setUserDict(crDict['_userDict'])
146 except KeyError:
147 pass
148
149 return cr
150