def to_string(self, employee): '''Convert each Employee to a list of [name, value] pairs. Note the final converter.to_string() call to ensure that the contents of the returned lists are str-converted''' dict_items = employee.as_dict().items converter = converter_for(list) return converter.to_string([[key, value] \ for key, value in dict_items()])
def query(self): s3 = boto.connect_s3() b = s3.get_bucket(self.bucket) res = [[['Path',x.key]] for x in b.list(self.prefix)] converter = converter_for(list) return converter.to_string(res)
def query(self): s3 = boto.connect_s3() bs = s3.get_all_buckets() res = [[['Name',x.name]] for x in bs] converter = converter_for(list) return converter.to_string(res)
def converters_are_thread_local(): ''' Registered converters should be thread-local: a converter registered in one thread should be isolated from those registered in other threads''' def yes_no(): ''' method to register a converter in a separate thread ''' register_converter(bool, YesNoConverter()) other_converter = converter_for(bool) lancelot.Spec(other_converter).it().should_be(Type(YesNoConverter)) yes_no_thread = threading.Thread(target=yes_no) yes_no_thread.start() yes_no_thread.join() lancelot.Spec(converter_for(bool)).it().should_be(Type(TrueFalseConverter))
def yes_no(): ''' method to register a converter in a separate thread ''' register_converter(bool, YesNoConverter()) other_converter = converter_for(bool) lancelot.Spec(other_converter).it().should_be(Type(YesNoConverter))
def to_string(self, obj): dict_items = obj.as_dict().items converter = converter_for(list) return converter.to_string([[key, value] for key, value in dict_items()])