Thanks for all your help and I'm glad that I could be of assistance!
Cheers,
Marc
On Fri, Dec 13, 2013 at 12:37 PM, Geoff Bache <email address hidden> wrote:
> I just fixed this. And then I noticed your patches here, which Launchpad
> hadn't mailed me about for some reason...
>
> I think mine is slightly more generic in that it handles multiple base
> classes and lets the existing mechanism find and import everything. But
> I had a rather dense line so I included three of yours to make it more
> readable.
>
> Thanks for your efforts here, hopefully it will work for real now!
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1256218
>
> Title:
> Metaclass exception when accessing headers attribute of a requests
> response
>
> Status in CaptureMock:
> Fix Committed
>
> Bug description:
> Given the following program:
>
> ```
> (capturemock)marca@marca-mac2:~/capturemock/requests$ cat test.py
> from capturemock import capturemock
>
> @capturemock("requests")
> def do_stuff():
> import requests
>
> resp = requests.get("http://www.google.com/")
> print(resp)
> print(resp.headers)
>
>
> do_stuff()
> ```
>
> ```
> (capturemock)marca@marca-mac2:~/capturemock/requests$ python test.py
> <Response [200]>
> CaseInsensitiveDict({'alternate-protocol': '80:quic',
> 'x-xss-protection': '1; mode=block', 'transfer-encoding': 'chunked',
> 'set-cookie':
> 'PREF=ID=7e28a73323b44303:FF=0:TM=1385711443:LM=1385711443:S=PLAZXhxGUX2EjpFr;
> expires=Sun, 29-Nov-2015 07:50:43 GMT; path=/; domain=.google.com,
> NID=67=ELE4eygYpLp0amsGQzpsg8OjGHrHuf3EVjzChdR9fjkbgRkHqoK1p68w--nDM8r-CdPKNae5llmovNXuNH_vnphKKOfyf7dfXXSsut7mMhebRTpdN_UbljHzjmIaTaqd;
> expires=Sat, 31-May-2014 07:50:43 GMT; path=/; domain=.google.com;
> HttpOnly', 'expires': '-1', 'server': 'gws', 'cache-control': 'private,
> max-age=0', 'date': 'Fri, 29 Nov 2013 07:50:43 GMT', 'p3p': 'CP="This is
> not a P3P policy! See
> http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657for more info."', 'content-type': 'text/html; charset=ISO-8859-1',
> 'x-frame-options': 'SAMEORIGIN'})
> ```
>
> works fine but if setting CAPTUREMOCK_MODE=1, it fails:
>
> ```
> (capturemock)marca@marca-mac2:~/capturemock/requests$
> CAPTUREMOCK_MODE=1 python test.py
> <Response [200]>
> Traceback (most recent call last):
> File "test.py", line 12, in <module>
> do_stuff()
> File "/Users/marca/dev/bzr-repos/capturemock/capturemock/__init__.py",
> line 210, in wrapped_func
> result = func(*funcargs, **funckw)
> File "test.py", line 9, in do_stuff
> print(resp.headers)
> File
> "/Users/marca/dev/bzr-repos/capturemock/capturemock/pythonclient.py", line
> 197, in __getattribute__
> return self.__getattr__(attrname)
> File
> "/Users/marca/dev/bzr-repos/capturemock/capturemock/pythonclient.py", line
> 90, in __getattr__
> self.captureMockTarget)
> File
> "/Users/marca/dev/bzr-repos/capturemock/capturemock/pythontraffic.py", line
> 530, in getAttribute
> return self.getAndRecordRealAttribute(traffic, proxyTarget,
> attrName, proxy, fullAttrName)
> File
> "/Users/marca/dev/bzr-repos/capturemock/capturemock/pythontraffic.py", line
> 574, in getAndRecordRealAttribute
> return self.transformResponse(traffic, realAttr, proxy)
> File
> "/Users/marca/dev/bzr-repos/capturemock/capturemock/pythontraffic.py", line
> 595, in transformResponse
> responseText, transformedResponse =
> traffic.transformResponse(response, proxy)
> File
> "/Users/marca/dev/bzr-repos/capturemock/capturemock/pythontraffic.py", line
> 230, in transformResponse
> transformedResponse = self.transformStructure(wrappedValue,
> self.insertProxy, proxy)
> File
> "/Users/marca/dev/bzr-repos/capturemock/capturemock/pythontraffic.py", line
> 242, in transformStructure
> return transformMethod(result, *args)
> File
> "/Users/marca/dev/bzr-repos/capturemock/capturemock/pythontraffic.py", line
> 252, in insertProxy
> return result.createProxy(proxy)
> File
> "/Users/marca/dev/bzr-repos/capturemock/capturemock/pythontraffic.py", line
> 97, in createProxy
> return proxy.captureMockCreateInstanceProxy(self.name, self.target,
> self.classDesc)
> File
> "/Users/marca/dev/bzr-repos/capturemock/capturemock/pythonclient.py", line
> 94, in captureMockCreateInstanceProxy
> newClass = self.captureMockNameFinder.makeClass(classDesc)
> File
> "/Users/marca/dev/bzr-repos/capturemock/capturemock/pythonclient.py", line
> 36, in makeClass
> return self.defineClass(actualClassName, classDefStr)
> File
> "/Users/marca/dev/bzr-repos/capturemock/capturemock/pythonclient.py", line
> 16, in defineClass
> self.defineClassLocally(classDefStr)
> File
> "/Users/marca/dev/bzr-repos/capturemock/capturemock/pythonclient.py", line
> 49, in defineClassLocally
> exec(classDefStr, self)
> File "<string>", line 1, in <module>
> TypeError: Error when calling the metaclass bases
> metaclass conflict: the metaclass of a derived class must be a
> (non-strict) subclass of the metaclasses of all its bases
> ```
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/capturemock/+bug/1256218/+subscriptions
>
Yep, it appears to work now!
Check this out:
https:/ /github. com/msabramo/ capturemock_ examples
Thanks for all your help and I'm glad that I could be of assistance!
Cheers,
Marc
On Fri, Dec 13, 2013 at 12:37 PM, Geoff Bache <email address hidden> wrote:
> I just fixed this. And then I noticed your patches here, which Launchpad /bugs.launchpad .net/bugs/ 1256218 marca@marca- mac2:~/ capturemock/ requests$ cat test.py "requests" ) www.google. com/") marca@marca- mac2:~/ capturemock/ requests$ python test.py Dict({' alternate- protocol' : '80:quic', encoding' : 'chunked', 7e28a73323b4430 3:FF=0: TM=1385711443: LM=1385711443: S=PLAZXhxGUX2Ej pFr; ELE4eygYpLp0ams GQzpsg8OjGHrHuf 3EVjzChdR9fjkbg RkHqoK1p68w- -nDM8r- CdPKNae5llmovNX uNH_vnphKKOfyf7 dfXXSsut7mMhebR TpdN_UbljHzjmIa Taqd; www.google. com/support/ accounts/ bin/answer. py?hl=en& answer= 151657for more info."', 'content-type': 'text/html; charset= ISO-8859- 1', marca@marca- mac2:~/ capturemock/ requests$ marca/dev/ bzr-repos/ capturemock/ capturemock/ __init_ _.py", marca/dev/ bzr-repos/ capturemock/ capturemock/ pythonclient. py", line getattr_ _(attrname) marca/dev/ bzr-repos/ capturemock/ capturemock/ pythonclient. py", line kTarget) marca/dev/ bzr-repos/ capturemock/ capturemock/ pythontraffic. py", line rdRealAttribute (traffic, proxyTarget, marca/dev/ bzr-repos/ capturemock/ capturemock/ pythontraffic. py", line lAttribute esponse( traffic, realAttr, proxy) marca/dev/ bzr-repos/ capturemock/ capturemock/ pythontraffic. py", line transformRespon se(response, proxy) marca/dev/ bzr-repos/ capturemock/ capturemock/ pythontraffic. py", line tructure( wrappedValue, marca/dev/ bzr-repos/ capturemock/ capturemock/ pythontraffic. py", line (result, *args) marca/dev/ bzr-repos/ capturemock/ capturemock/ pythontraffic. py", line createProxy( proxy) marca/dev/ bzr-repos/ capturemock/ capturemock/ pythontraffic. py", line ckCreateInstanc eProxy( self.name, self.target, marca/dev/ bzr-repos/ capturemock/ capturemock/ pythonclient. py", line teInstanceProxy kNameFinder. makeClass( classDesc) marca/dev/ bzr-repos/ capturemock/ capturemock/ pythonclient. py", line s(actualClassNa me, classDefStr) marca/dev/ bzr-repos/ capturemock/ capturemock/ pythonclient. py", line sLocally( classDefStr) marca/dev/ bzr-repos/ capturemock/ capturemock/ pythonclient. py", line /bugs.launchpad .net/capturemoc k/+bug/ 1256218/ +subscriptions
> hadn't mailed me about for some reason...
>
> I think mine is slightly more generic in that it handles multiple base
> classes and lets the existing mechanism find and import everything. But
> I had a rather dense line so I included three of yours to make it more
> readable.
>
> Thanks for your efforts here, hopefully it will work for real now!
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https:/
>
> Title:
> Metaclass exception when accessing headers attribute of a requests
> response
>
> Status in CaptureMock:
> Fix Committed
>
> Bug description:
> Given the following program:
>
> ```
> (capturemock)
> from capturemock import capturemock
>
> @capturemock(
> def do_stuff():
> import requests
>
> resp = requests.get("http://
> print(resp)
> print(resp.headers)
>
>
> do_stuff()
> ```
>
> ```
> (capturemock)
> <Response [200]>
> CaseInsensitive
> 'x-xss-protection': '1; mode=block', 'transfer-
> 'set-cookie':
> 'PREF=ID=
> expires=Sun, 29-Nov-2015 07:50:43 GMT; path=/; domain=.google.com,
> NID=67=
> expires=Sat, 31-May-2014 07:50:43 GMT; path=/; domain=.google.com;
> HttpOnly', 'expires': '-1', 'server': 'gws', 'cache-control': 'private,
> max-age=0', 'date': 'Fri, 29 Nov 2013 07:50:43 GMT', 'p3p': 'CP="This is
> not a P3P policy! See
> http://
> 'x-frame-options': 'SAMEORIGIN'})
> ```
>
> works fine but if setting CAPTUREMOCK_MODE=1, it fails:
>
> ```
> (capturemock)
> CAPTUREMOCK_MODE=1 python test.py
> <Response [200]>
> Traceback (most recent call last):
> File "test.py", line 12, in <module>
> do_stuff()
> File "/Users/
> line 210, in wrapped_func
> result = func(*funcargs, **funckw)
> File "test.py", line 9, in do_stuff
> print(resp.headers)
> File
> "/Users/
> 197, in __getattribute__
> return self.__
> File
> "/Users/
> 90, in __getattr__
> self.captureMoc
> File
> "/Users/
> 530, in getAttribute
> return self.getAndReco
> attrName, proxy, fullAttrName)
> File
> "/Users/
> 574, in getAndRecordRea
> return self.transformR
> File
> "/Users/
> 595, in transformResponse
> responseText, transformedResponse =
> traffic.
> File
> "/Users/
> 230, in transformResponse
> transformedResponse = self.transformS
> self.insertProxy, proxy)
> File
> "/Users/
> 242, in transformStructure
> return transformMethod
> File
> "/Users/
> 252, in insertProxy
> return result.
> File
> "/Users/
> 97, in createProxy
> return proxy.captureMo
> self.classDesc)
> File
> "/Users/
> 94, in captureMockCrea
> newClass = self.captureMoc
> File
> "/Users/
> 36, in makeClass
> return self.defineClas
> File
> "/Users/
> 16, in defineClass
> self.defineClas
> File
> "/Users/
> 49, in defineClassLocally
> exec(classDefStr, self)
> File "<string>", line 1, in <module>
> TypeError: Error when calling the metaclass bases
> metaclass conflict: the metaclass of a derived class must be a
> (non-strict) subclass of the metaclasses of all its bases
> ```
>
> To manage notifications about this bug go to:
> https:/
>