Luke Plant avatar Luke Plant committed 391c880

Changed 'varchar' to do max_length introspection at runtime.

Comments (0)

Files changed (3)

+Version 0.1.2
+-------------
+
+* Changed 'varchar' field to do max_length introspection at runtime.
+  This breaks the previous signature of the function.
+
 
 Version 0.1.1
 -------------

anonymizer/base.py

 
     ### Public interace ##
 
-    def varchar(self, max_length, field=None):
+    def varchar(self, field=None):
         """
         Returns a chunk of text, of maximum length 'max_length'
         """
+        assert field is not None, "The field parameter must be passed to the 'varchar' method."
+        max_length = field.max_length
         def source():
             length = random.choice(range(0, max_length + 1))
             return "".join(random.choice(general_chars) for i in xrange(length))

anonymizer/introspect.py

             return '"lorem"'
 
         # Just try some random chars
-        max_length = field.max_length
-        return "lambda self, obj, field, val: self.faker.varchar(%d, field=field)" % max_length
+        return '"varchar"'
 
 
     try:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.