mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	decode bytecode in string
Signed-off-by: Florian Brandes <florian.brandes@posteo.de>
This commit is contained in:
		@@ -83,9 +83,10 @@ def barcode_reader(image) -> list:
 | 
			
		||||
        # Traverse through all the detected barcodes in image
 | 
			
		||||
        for barcode in detected_barcodes:
 | 
			
		||||
            if barcode.data:
 | 
			
		||||
                barcodes.append(str(barcode.data))
 | 
			
		||||
                decoded_barcode = barcode.data.decode("utf-8")
 | 
			
		||||
                barcodes.append(decoded_barcode)
 | 
			
		||||
                logger.debug(
 | 
			
		||||
                    f"Barcode of type {str(barcode.type)} found: {str(barcode.data)}",
 | 
			
		||||
                    f"Barcode of type {str(barcode.type)} found: {decoded_barcode}",
 | 
			
		||||
                )
 | 
			
		||||
    return barcodes
 | 
			
		||||
 | 
			
		||||
@@ -96,7 +97,7 @@ def scan_file_for_separating_barcodes(filepath: str) -> list:
 | 
			
		||||
    Returns a list of pagenumbers, which separate the file
 | 
			
		||||
    """
 | 
			
		||||
    separator_page_numbers = []
 | 
			
		||||
    separator_barcode = "b'" + str(settings.CONSUMER_BARCODE_STRING) + "'"
 | 
			
		||||
    separator_barcode = str(settings.CONSUMER_BARCODE_STRING)
 | 
			
		||||
    # use a temporary directory in case the file os too big to handle in memory
 | 
			
		||||
    with tempfile.TemporaryDirectory() as path:
 | 
			
		||||
        pages_from_path = convert_from_path(filepath, output_folder=path)
 | 
			
		||||
 
 | 
			
		||||
@@ -98,7 +98,7 @@ class TestTasks(DirectoriesMixin, TestCase):
 | 
			
		||||
            "patch-code-t.pbm",
 | 
			
		||||
        )
 | 
			
		||||
        img = Image.open(test_file)
 | 
			
		||||
        separator_barcode = "b'" + str(settings.CONSUMER_BARCODE_STRING) + "'"
 | 
			
		||||
        separator_barcode = str(settings.CONSUMER_BARCODE_STRING)
 | 
			
		||||
        self.assertEqual(tasks.barcode_reader(img), [separator_barcode])
 | 
			
		||||
 | 
			
		||||
    def test_barcode_reader2(self):
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user