prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  es_ES postalcode is not generating valid codes
  * Faker version: 11.3
  * OS: Any
  
  When using postcode for es_ES and using it with a field that requires a valid Postal Code, it fails sometimes.
  I will assume that there is no logic with postal code generation for Spain.
  
  ### Steps to reproduce
  
  Generate postal codes
  
  ### Expected behavior
  
  Get a valid Spain postal code
  
  ### Actual behavior
  
  Unexpected. Many are wrong
  
  ----
  
  I'll dig now into the code. Let's see if I can get some more information and fix it :thinking: Do not expect much from me
  
  </issue>
  <code>
  [start of faker/providers/address/es_ES/__init__.py]
  1 from ..es import Provider as AddressProvider
  2 
  3 
  4 class Provider(AddressProvider):
  5     building_number_formats = ("%", "%#", "%#", "%#", "%##")
  6     street_prefixes = (
  7         "Plaza",
  8         "Calle",
  9         "Avenida",
  10         "Via",
  11         "Vial",
  12         "Rambla",
  13         "Glorieta",
  14         "Urbanización",
  15         "Callejón",
  16         "Cañada",
  17         "Alameda",
  18         "Acceso",
  19         "C.",
  20         "Ronda",
  21         "Pasaje",
  22         "Cuesta",
  23         "Pasadizo",
  24         "Paseo",
  25         "Camino",
  26     )
  27     postcode_formats = ("#####",)
  28     states = (
  29         "Álava",
  30         "Albacete",
  31         "Alicante",
  32         "Almería",
  33         "Asturias",
  34         "Ávila",
  35         "Badajoz",
  36         "Baleares",
  37         "Barcelona",
  38         "Burgos",
  39         "Cáceres",
  40         "Cádiz",
  41         "Cantabria",
  42         "Castellón",
  43         "Ceuta",
  44         "Ciudad",
  45         "Córdoba",
  46         "Cuenca",
  47         "Girona",
  48         "Granada",
  49         "Guadalajara",
  50         "Guipúzcoa",
  51         "Huelva",
  52         "Huesca",
  53         "Jaén",
  54         "La Coruña",
  55         "La Rioja",
  56         "Las Palmas",
  57         "León",
  58         "Lleida",
  59         "Lugo",
  60         "Madrid",
  61         "Málaga",
  62         "Melilla",
  63         "Murcia",
  64         "Navarra",
  65         "Ourense",
  66         "Palencia",
  67         "Pontevedra",
  68         "Salamanca",
  69         "Santa Cruz de Tenerife",
  70         "Segovia",
  71         "Sevilla",
  72         "Soria",
  73         "Tarragona",
  74         "Teruel",
  75         "Toledo",
  76         "Valencia",
  77         "Valladolid",
  78         "Vizcaya",
  79         "Zamora",
  80         "Zaragoza",
  81     )
  82 
  83     # Source:
  84     # https://administracionelectronica.gob.es/ctt/resources/Soluciones
  85     # /238/Descargas/Catalogo-de-Comunidades-Autonomas.xlsx
  86     regions = (
  87         "Andalucía",
  88         "Aragón",
  89         "Principado de Asturias",
  90         "Illes Balears",
  91         "Canarias",
  92         "Cantabria",
  93         "Castilla y León",
  94         "Castilla-La Mancha",
  95         "Cataluña",
  96         "Comunitat Valenciana",
  97         "Extremadura",
  98         "Galicia",
  99         "Comunidad de Madrid",
  100         "Región de Murcia",
  101         "Comunidad Foral de Navarra",
  102         "País Vasco",
  103         "La Rioja",
  104         "Ciudad Autónoma de Ceuta",
  105         "Ciudad Autónoma de Melilla",
  106     )
  107 
  108     city_formats = ("{{state_name}}",)
  109 
  110     street_name_formats = (
  111         "{{street_prefix}} {{first_name}} {{last_name}}",
  112         "{{street_prefix}} de {{first_name}} {{last_name}}",
  113     )
  114     street_address_formats = (
  115         "{{street_name}} {{building_number}}",
  116         "{{street_name}} {{building_number}} {{secondary_address}} ",
  117     )
  118     address_formats = ("{{street_address}}\n{{city}}, {{postcode}}",)
  119     secondary_address_formats = ("Apt. ##", "Piso #", "Puerta #")
  120 
  121     def state_name(self) -> str:
  122         return self.random_element(self.states)
  123 
  124     def street_prefix(self) -> str:
  125         return self.random_element(self.street_prefixes)
  126 
  127     def secondary_address(self) -> str:
  128         return self.numerify(self.random_element(self.secondary_address_formats))
  129 
  130     def administrative_unit(self) -> str:
  131         return self.random_element(self.states)
  132 
  133     state = administrative_unit
  134 
  135     def region(self) -> str:
  136         return self.random_element(self.regions)
  137 
  138     autonomous_community = region
  139
  [end of faker/providers/address/es_ES/__init__.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/faker/providers/address/es_ES/__init__.py b/faker/providers/address/es_ES/__init__.py
  --- a/faker/providers/address/es_ES/__init__.py
  +++ b/faker/providers/address/es_ES/__init__.py
  @@ -24,7 +24,6 @@
           "Paseo",
           "Camino",
       )
  -    postcode_formats = ("#####",)
       states = (
           "Álava",
           "Albacete",
  @@ -135,4 +134,7 @@
       def region(self) -> str:
           return self.random_element(self.regions)
   
  +    def postcode(self) -> str:
  +        return str(self.generator.random.randint(1000, 52100)).zfill(5)
  +
       autonomous_community = region
  
verification_info: {"golden_diff": "diff --git a/faker/providers/address/es_ES/__init__.py b/faker/providers/address/es_ES/__init__.py\n--- a/faker/providers/address/es_ES/__init__.py\n+++ b/faker/providers/address/es_ES/__init__.py\n@@ -24,7 +24,6 @@\n         \"Paseo\",\n         \"Camino\",\n     )\n-    postcode_formats = (\"#####\",)\n     states = (\n         \"\u00c1lava\",\n         \"Albacete\",\n@@ -135,4 +134,7 @@\n     def region(self) -> str:\n         return self.random_element(self.regions)\n \n+    def postcode(self) -> str:\n+        return str(self.generator.random.randint(1000, 52100)).zfill(5)\n+\n     autonomous_community = region\n", "issue": "es_ES postalcode is not generating valid codes\n* Faker version: 11.3\r\n* OS: Any\r\n\r\nWhen using postcode for es_ES and using it with a field that requires a valid Postal Code, it fails sometimes.\r\nI will assume that there is no logic with postal code generation for Spain.\r\n\r\n### Steps to reproduce\r\n\r\nGenerate postal codes\r\n\r\n### Expected behavior\r\n\r\nGet a valid Spain postal code\r\n\r\n### Actual behavior\r\n\r\nUnexpected. Many are wrong\r\n\r\n----\r\n\r\nI'll dig now into the code. Let's see if I can get some more information and fix it :thinking: Do not expect much from me\n", "before_files": [{"content": "from ..es import Provider as AddressProvider\n\n\nclass Provider(AddressProvider):\n    building_number_formats = (\"%\", \"%#\", \"%#\", \"%#\", \"%##\")\n    street_prefixes = (\n        \"Plaza\",\n        \"Calle\",\n        \"Avenida\",\n        \"Via\",\n        \"Vial\",\n        \"Rambla\",\n        \"Glorieta\",\n        \"Urbanizaci\u00f3n\",\n        \"Callej\u00f3n\",\n        \"Ca\u00f1ada\",\n        \"Alameda\",\n        \"Acceso\",\n        \"C.\",\n        \"Ronda\",\n        \"Pasaje\",\n        \"Cuesta\",\n        \"Pasadizo\",\n        \"Paseo\",\n        \"Camino\",\n    )\n    postcode_formats = (\"#####\",)\n    states = (\n        \"\u00c1lava\",\n        \"Albacete\",\n        \"Alicante\",\n        \"Almer\u00eda\",\n        \"Asturias\",\n        \"\u00c1vila\",\n        \"Badajoz\",\n        \"Baleares\",\n        \"Barcelona\",\n        \"Burgos\",\n        \"C\u00e1ceres\",\n        \"C\u00e1diz\",\n        \"Cantabria\",\n        \"Castell\u00f3n\",\n        \"Ceuta\",\n        \"Ciudad\",\n        \"C\u00f3rdoba\",\n        \"Cuenca\",\n        \"Girona\",\n        \"Granada\",\n        \"Guadalajara\",\n        \"Guip\u00fazcoa\",\n        \"Huelva\",\n        \"Huesca\",\n        \"Ja\u00e9n\",\n        \"La Coru\u00f1a\",\n        \"La Rioja\",\n        \"Las Palmas\",\n        \"Le\u00f3n\",\n        \"Lleida\",\n        \"Lugo\",\n        \"Madrid\",\n        \"M\u00e1laga\",\n        \"Melilla\",\n        \"Murcia\",\n        \"Navarra\",\n        \"Ourense\",\n        \"Palencia\",\n        \"Pontevedra\",\n        \"Salamanca\",\n        \"Santa Cruz de Tenerife\",\n        \"Segovia\",\n        \"Sevilla\",\n        \"Soria\",\n        \"Tarragona\",\n        \"Teruel\",\n        \"Toledo\",\n        \"Valencia\",\n        \"Valladolid\",\n        \"Vizcaya\",\n        \"Zamora\",\n        \"Zaragoza\",\n    )\n\n    # Source:\n    # https://administracionelectronica.gob.es/ctt/resources/Soluciones\n    # /238/Descargas/Catalogo-de-Comunidades-Autonomas.xlsx\n    regions = (\n        \"Andaluc\u00eda\",\n        \"Arag\u00f3n\",\n        \"Principado de Asturias\",\n        \"Illes Balears\",\n        \"Canarias\",\n        \"Cantabria\",\n        \"Castilla y Le\u00f3n\",\n        \"Castilla-La Mancha\",\n        \"Catalu\u00f1a\",\n        \"Comunitat Valenciana\",\n        \"Extremadura\",\n        \"Galicia\",\n        \"Comunidad de Madrid\",\n        \"Regi\u00f3n de Murcia\",\n        \"Comunidad Foral de Navarra\",\n        \"Pa\u00eds Vasco\",\n        \"La Rioja\",\n        \"Ciudad Aut\u00f3noma de Ceuta\",\n        \"Ciudad Aut\u00f3noma de Melilla\",\n    )\n\n    city_formats = (\"{{state_name}}\",)\n\n    street_name_formats = (\n        \"{{street_prefix}} {{first_name}} {{last_name}}\",\n        \"{{street_prefix}} de {{first_name}} {{last_name}}\",\n    )\n    street_address_formats = (\n        \"{{street_name}} {{building_number}}\",\n        \"{{street_name}} {{building_number}} {{secondary_address}} \",\n    )\n    address_formats = (\"{{street_address}}\\n{{city}}, {{postcode}}\",)\n    secondary_address_formats = (\"Apt. ##\", \"Piso #\", \"Puerta #\")\n\n    def state_name(self) -> str:\n        return self.random_element(self.states)\n\n    def street_prefix(self) -> str:\n        return self.random_element(self.street_prefixes)\n\n    def secondary_address(self) -> str:\n        return self.numerify(self.random_element(self.secondary_address_formats))\n\n    def administrative_unit(self) -> str:\n        return self.random_element(self.states)\n\n    state = administrative_unit\n\n    def region(self) -> str:\n        return self.random_element(self.regions)\n\n    autonomous_community = region\n", "path": "faker/providers/address/es_ES/__init__.py"}]}