Skip to content

Commit 4543da7

Browse files
author
whitie
committed
Finished moving codes to own subpackage.
1 parent c192f8e commit 4543da7

6 files changed

Lines changed: 46 additions & 31 deletions

File tree

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ Interactive::
5050

5151
>>> import barcode
5252
>>> barcode.PROVIDED_BARCODES
53-
[u'code39', u'ean', u'ean13', u'ean8', u'gs1', u'gtin', u'isbn', u'isbn10',
54-
u'isbn13', u'issn', u'jan', u'pzn', u'upc', u'upca']
53+
[u'code39', u'code128', u'ean', u'ean13', u'ean8', u'gs1', u'gtin',
54+
u'isbn', u'isbn10', u'isbn13', u'issn', u'jan', u'pzn', u'upc', u'upca']
5555
>>> EAN = barcode.get_barcode_class('ean13')
5656
>>> EAN
5757
<class 'barcode.ean.EuropeanArticleNumber13'>

barcode/charsets/ean.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from __future__ import unicode_literals
4+
5+
6+
EDGE = '101'
7+
MIDDLE = '01010'
8+
CODES = {
9+
'A': ('0001101', '0011001', '0010011', '0111101', '0100011',
10+
'0110001', '0101111', '0111011', '0110111', '0001011'),
11+
'B': ('0100111', '0110011', '0011011', '0100001', '0011101',
12+
'0111001', '0000101', '0010001', '0001001', '0010111'),
13+
'C': ('1110010', '1100110', '1101100', '1000010', '1011100',
14+
'1001110', '1010000', '1000100', '1001000', '1110100'),
15+
}
16+
LEFT_PATTERN = ('AAAAAA', 'AABABB', 'AABBAB', 'AABBBA', 'ABAABB',
17+
'ABBAAB', 'ABBBAA', 'ABABAB', 'ABABBA', 'ABBABA')

barcode/codex.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,8 @@ def build(self):
244244
code += code128.STOP
245245
code += '11'
246246
return [code]
247+
248+
def render(self, writer_options):
249+
options = dict(module_width=MIN_SIZE, quiet_zone=MIN_QUIET_ZONE)
250+
options.update(writer_options or {})
251+
return Barcode.render(self, options)

barcode/ean.py

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
from __future__ import unicode_literals
44

5-
"""barcode.ean
5+
"""Module: barcode.ean
66
7+
:Provided barcodes: EAN-13, EAN-8, JAN
78
"""
89

910
from barcode.base import Barcode
11+
from barcode.charsets import ean as _ean
1012
from barcode.errors import *
1113

1214
# Python 3
@@ -19,18 +21,6 @@
1921
# EAN13 Specs (all sizes in mm)
2022
SIZES = dict(SC0=0.27, SC1=0.297, SC2=0.33, SC3=0.363, SC4=0.396, SC5=0.445,
2123
SC6=0.495, SC7=0.544, SC8=0.61, SC9=0.66)
22-
EDGE = '101'
23-
MIDDLE = '01010'
24-
CODES = {
25-
'A': ('0001101', '0011001', '0010011', '0111101', '0100011',
26-
'0110001', '0101111', '0111011', '0110111', '0001011'),
27-
'B': ('0100111', '0110011', '0011011', '0100001', '0011101',
28-
'0111001', '0000101', '0010001', '0001001', '0010111'),
29-
'C': ('1110010', '1100110', '1101100', '1000010', '1011100',
30-
'1001110', '1010000', '1000100', '1001000', '1110100'),
31-
}
32-
LEFT_PATTERN = ('AAAAAA', 'AABABB', 'AABBAB', 'AABBBA', 'ABAABB',
33-
'ABBAAB', 'ABBBAA', 'ABABAB', 'ABABBA', 'ABBABA')
3424

3525

3626
class EuropeanArticleNumber13(Barcode):
@@ -50,7 +40,7 @@ class EuropeanArticleNumber13(Barcode):
5040
def __init__(self, ean, writer=None):
5141
ean = ean[:self.digits]
5242
if not ean.isdigit():
53-
raise IllegalCharacterError('Code can only contain numbers.')
43+
raise IllegalCharacterError('EAN code can only contain numbers.')
5444
self.ean = ean
5545
self.ean = '{0}{1}'.format(ean, self.calculate_checksum())
5646
self.writer = writer or Barcode.default_writer()
@@ -80,14 +70,14 @@ def build(self):
8070
:returns: The pattern as string
8171
:rtype: String
8272
"""
83-
code = EDGE[:]
84-
pattern = LEFT_PATTERN[int(self.ean[0])]
73+
code = _ean.EDGE[:]
74+
pattern = _ean.LEFT_PATTERN[int(self.ean[0])]
8575
for i, number in enumerate(self.ean[1:7]):
86-
code += CODES[pattern[i]][int(number)]
87-
code += MIDDLE
76+
code += _ean.CODES[pattern[i]][int(number)]
77+
code += _ean.MIDDLE
8878
for number in self.ean[7:]:
89-
code += CODES['C'][int(number)]
90-
code += EDGE
79+
code += _ean.CODES['C'][int(number)]
80+
code += _ean.EDGE
9181
return [code]
9282

9383
def to_ascii(self):
@@ -122,8 +112,8 @@ class JapanArticleNumber(EuropeanArticleNumber13):
122112

123113
def __init__(self, jan, writer=None):
124114
if int(jan[:3]) not in JapanArticleNumber.valid_country_codes:
125-
raise WrongCountryCodeError("Country code isn't between 450-460 or "
126-
"490-500.")
115+
raise WrongCountryCodeError("Country code isn't between 450-460 "
116+
"or 490-500.")
127117
EuropeanArticleNumber13.__init__(self, jan, writer)
128118

129119

@@ -161,13 +151,13 @@ def build(self):
161151
:returns: The pattern as string
162152
:rtype: String
163153
"""
164-
code = EDGE[:]
154+
code = _ean.EDGE[:]
165155
for number in self.ean[:4]:
166-
code += CODES['A'][int(number)]
167-
code += MIDDLE
156+
code += _ean.CODES['A'][int(number)]
157+
code += _ean.MIDDLE
168158
for number in self.ean[4:]:
169-
code += CODES['C'][int(number)]
170-
code += EDGE
159+
code += _ean.CODES['C'][int(number)]
160+
code += _ean.EDGE
171161
return [code]
172162

173163

barcode/isxn.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
from __future__ import unicode_literals
44

5-
"""barcode.isxn
5+
"""Module: barcode.isxn
6+
7+
:Provided barcodes: ISBN-13, ISBN-10, ISSN
68
79
This module provides some special codes, which are no standalone barcodes.
810
All codes where transformed to EAN-13 barcodes. In every case, the checksum

barcode/upc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
from __future__ import unicode_literals
44

5-
"""barcode.upc
5+
"""Module: barcode.upc
66
7+
:Provided barcodes: UPC-A
78
"""
89
__docformat__ = 'restructuredtext en'
910

0 commit comments

Comments
 (0)