Syntax Parameters
Syntax contains parameters that are used in reading or writing edi-files.
The complete list of syntax parameters including default values is in bots/grammar.py (in the classes of the editypes).
Syntax is a python dict (dictionary).
Example of syntax parameters:
syntax = {
'charset' : 'utf-8', #character set is utf-8
'checkfixedrecordtooshort' : True, #check if fixed record is to short
'indented' : True, #xml: produced indented output
'decimaal' : ',', #decimal sign is ', '
}
Usage and Overriding
Syntax parameters can be set at different places; these settings override (somewhat like CSS). The order in which overriding is done:
default values are in
bots/grammars.py(per editype). Do not change these values here.envelope grammar (eg for x12:
bots/usersys/grammars/x12/x12.py, for edifact:bots/usersys/grammars/edifact/edifact.py)message grammar
frompartner grammar (eg in
bots/usersys/partners/x12/partnerID.py)topartner grammar (eg in
bots/usersys/partners/x12/partnerID.py)
Example 1: edifact charset
default value is UNOA
value in envelope (
edifact.py) is UNOAfor invoices: a description is used so the message grammar for invoices has charset UNOC
retailer ABC insists on receiving invoices as UNOA, so this is indicated in the topartner grammar.
Example 2: x12 element separator
in grammar.py:
'field_sep':'*'(bots default value)in x12.py:
'field_sep':'|'(default value company uses when sending x12)retailer ABC insists:
'field_sep':'\x07'(that is\a, or BEL)
List of most useful Syntax Parameters
Parameter |
Direction |
Description |
|---|---|---|
add_crlfafterrecord_sep |
Out |
Put an extra character after a record/segment separator. Value: string, typically |
acceptspaceinnumfield |
In |
Do not raise error when numeric field contains only spaces but assume value is 0. |
allow_lastrecordnotclosedproperly |
In |
(csv) Allows last record not to have record separator. |
charset |
In |
Charset to use; (edifact, xml) is overridden by charset-declaration in content. |
Out |
Charset to use in output. Bots is quite strict in this. |
|
checkcharsetin |
In |
What to do for chars not in charset. Possible values ‘strict’ (gives error) or ‘ignore’ (skip the characters not in the charset) or ‘botsreplace’ (replace with char as set in bots.ini; default is space) |
checkcharsetout |
Out |
What to do for chars not in charset. Possible values ‘strict’ (gives error) or ‘ignore’ (skip the characters not in the charset) or ‘botsreplace’ (replace with char as set in bots.ini; default is space) |
checkfixedrecordtoolong |
In |
(fixed) Warn if record is too long. Possible values: True/False, default: True. |
checkfixedrecordtooshort |
In |
(fixed) Warn if record is too short. Possible values: True/False, default: False. |
checkunknownentities |
In/Out |
(xml, json) Skip unknown attributes/elements (instead of raising an error). |
contenttype |
Out |
Content-type of translated file; used as mime-envelope of email. |
decimaal |
In/Out |
Decimal point; default is ‘.’. For edifact: read from UNA-string if present. |
endrecordID |
In |
(fixed) End position of record ID. Possible value: number, default 3. See startrecordID. |
envelope |
Out |
Envelope to use. If nothing specified: no envelope - files are just copied/appended. For csv output, use the value ‘csvheader’ to include a header line with field names. |
envelope-template |
Out |
(template/html) The template for the envelope. |
escape |
In/Out |
Escape character used. Default: edifact: ‘?’. |
field_sep |
In/Out |
Field separator. Default: edifact: ‘+’; csv: ‘:’ x12: ‘*’; tradacoms: ‘+’. |
forcequote |
Out |
(csv) Possible values: 1 (quote only if necessary); 1 (always quote), 2 (quote only alfanum). Default is 1. |
forceUNA |
Out |
(edifact) Always use UNA-segment in header, even if not needed. Possible values: True, False. Default: False. |
indented |
Out |
(xml, json) Indent message for human readability. Nice while testing. Indented messages are syntactically OK, but are much bigger. Possible values: True, False. Default: False. See also add_crlfafterrecord_sep. |
merge |
Out |
If merge is True: merge translated messages to one file (for same sender, receiver, messagetype, channel, etc). Related: envelope. Possible values: True, False. |
namespace_prefixes |
Out |
(xml) To over-ride default namespace prefixes (ns0, ns1, etc.) for outgoing xml. It is a list, consisting of tuples, each tuple consists of prefix and uri. Example: |
noBOTSID |
In/Out |
(csv) Use if records contain no real record ID. |
output |
Out |
(template) Possible value: ‘xhtml-strict’. |
pass_all |
In |
(csv, fixed) If only one recordtype and no nextmessageblock; False: pass record for record to mapping; True: Pass all records to mapping. |
preprocess_lex |
In |
Lex preprocessing via user exit with a callable. Default: False. |
preprocess_nodes |
In |
Node preprocessing via user exit with a callable. Default: False. |
quote_char |
In/Out |
(csv) Character used as quote symbol. Default: ‘’’ (single quote). |
record_sep |
In/Out |
Character used as record separator. Defaults: edifact: ‘’’ (single quote); fixed: ‘n’; x12: ‘~’. |
record_tag_sep |
Out |
(tradacoms) Separator used after segment tag. Defaults: ‘=’. |
replacechar |
Out |
(x12) If a separator value is found in the data, replace with this character. Default: ‘’ (raise error when separator value in data). |
skip_char |
In |
Character(s) to skip, not interpreted when reading file. Default in edifact, x12 and tradacoms: ‘rn’ |
skip_firstline |
In |
(csv) Skip first line (often contains field names). Possible values: True/False/Integer number of lines to skip, default: False. True skips 1 line. |
startrecordID |
In |
(fixed) Start position of record ID; Possible value: number, default 0. See endrecordID. |
strict_syntax_check |
In |
For files with variable lenght records, except CSV: don’t allow whitespaces between records, double record separators or alphanumeric repeating separator. Possible values: True/False. Default: False. |
strip_value |
In |
(csv, edifact, x12, tradacom) Possible values: True/False. True removes any leading, and trailing whitespaces from the record. Default: False. |
template_engine |
Out |
(template) Template to use for HTML-output. Possible values: django or genshi. Default: genshi. |
triad |
In |
Triad (thousands) symbol used (e.g. ‘1,000,048.35’). If specified, this symbol is skipped when parsing numbers. By default numbers are expected to come without thousands separators. |
version |
Out |
(edifact, x12) Version of standard generate. Value: string, typically: ‘3’ in edifact or ‘004010’ for x12. |
wrap_length |
Out |
Wraps the output to a new line when it exceeds this length. Possible value: number, default 0. Typically used in conjunction with ‘add_crlfafterrecord_sep’:’’ (blank). Note: does not affect envelope of message. |