]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
add note about hack
authorKevin McCarthy <me@kevinmccarthy.org>
Sat, 10 May 2014 21:35:09 +0000 (11:35 -1000)
committerKevin McCarthy <me@kevinmccarthy.org>
Sat, 10 May 2014 21:52:36 +0000 (11:52 -1000)
vcr/migration.py

index 421be0c4a7dc0dc302b9982dc72fe0a2e21b4d25..0b36284227e189e55232e9159accd038f981df4d 100644 (file)
@@ -31,7 +31,19 @@ except ImportError:
     from yaml import Loader
 
 def preprocess_yaml(cassette):
-    return cassette.replace(' !!python/object:vcr.request.Request', '').replace('!!python/object/apply:__builtin__.frozenset', '').replace('!!python/object/apply:builtins.frozenset', '')
+    # this is the hack that makes the whole thing work.  The old version used
+    # to deserialize to Request objects automatically using pyYaml's !!python
+    # tag system.  This made it difficult to deserialize old cassettes on new
+    # versions.  So this just strips the tags before deserializing.
+
+    STRINGS_TO_NUKE = [
+        '!!python/object:vcr.request.Request',
+        '!!python/object/apply:__builtin__.frozenset',
+        '!!python/object/apply:builtins.frozenset',
+    ]
+    for s in STRINGS_TO_NUKE:
+        cassette = cassette.replace(s, '')
+    return cassette
 
 
 PARTS = [