Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
codecs Namespace Reference

Data Structures

class  Codec
 Codec base classes (defining the API) More...
 
class  StreamWriter
 
class  StreamReader
 
class  StreamReaderWriter
 
class  StreamRecoder
 

Functions

def open
 
def EncodedFile
 
def getencoder
 Helpers for codec lookup. More...
 
def getdecoder
 
def getreader
 
def getwriter
 
def make_identity_dict
 Helpers for charmap-based codecs. More...
 
def make_encoding_map
 

Variables

list __all__
 
tuple BOM = struct.pack('=H', 0xFEFF)
 Constants. More...
 
string BOM_BE = '\376\377'
 
string BOM_LE = '\377\376'
 
string BOM64_BE = '\000\000\376\377'
 
string BOM64_LE = '\377\376\000\000'
 
int _false = 0
 

Detailed Description

codecs -- Python Codec Registry, API and helpers.


Written by Marc-Andre Lemburg (mal@lemburg.com).

(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.

Function Documentation

def codecs.EncodedFile (   file,
  data_encoding,
  file_encoding = None,
  errors = 'strict' 
)
Return a wrapped version of file which provides transparent
    encoding translation.

    Strings written to the wrapped file are interpreted according
    to the given data_encoding and then written to the original
    file as string using file_encoding. The intermediate encoding
    will usually be Unicode but depends on the specified codecs.

    Strings are read from the file using file_encoding and then
    passed back to the caller as string using data_encoding.

    If file_encoding is not given, it defaults to data_encoding.

    errors may be given to define the error handling. It defaults
    to 'strict' which causes ValueErrors to be raised in case an
    encoding error occurs.

    The returned wrapped file object provides two extra attributes
    .data_encoding and .file_encoding which reflect the given
    parameters of the same name. The attributes can be used for
    introspection by Python programs.

Definition at line 505 of file codecs.py.

References cgitb.lookup().

506 def EncodedFile(file, data_encoding, file_encoding=None, errors='strict'):
507 
508  """ Return a wrapped version of file which provides transparent
509  encoding translation.
510 
511  Strings written to the wrapped file are interpreted according
512  to the given data_encoding and then written to the original
513  file as string using file_encoding. The intermediate encoding
514  will usually be Unicode but depends on the specified codecs.
515 
516  Strings are read from the file using file_encoding and then
517  passed back to the caller as string using data_encoding.
518 
519  If file_encoding is not given, it defaults to data_encoding.
520 
521  errors may be given to define the error handling. It defaults
522  to 'strict' which causes ValueErrors to be raised in case an
523  encoding error occurs.
524 
525  The returned wrapped file object provides two extra attributes
526  .data_encoding and .file_encoding which reflect the given
527  parameters of the same name. The attributes can be used for
528  introspection by Python programs.
529 
530  """
531  if file_encoding is None:
532  file_encoding = data_encoding
533  encode, decode = lookup(data_encoding)[:2]
534  Reader, Writer = lookup(file_encoding)[2:]
535  sr = StreamRecoder(file,
536  encode, decode, Reader, Writer,
537  errors)
538  # Add attributes to simplify introspection
539  sr.data_encoding = data_encoding
540  sr.file_encoding = file_encoding
541  return sr
def codecs.getdecoder (   encoding)
Lookup up the codec for the given encoding and return
    its decoder function.

    Raises a LookupError in case the encoding cannot be found.

Definition at line 554 of file codecs.py.

References cgitb.lookup().

555 def getdecoder(encoding):
556 
557  """ Lookup up the codec for the given encoding and return
558  its decoder function.
559 
560  Raises a LookupError in case the encoding cannot be found.
561 
562  """
563  return lookup(encoding)[1]
def codecs.getencoder (   encoding)

Helpers for codec lookup.

Lookup up the codec for the given encoding and return
    its encoder function.

    Raises a LookupError in case the encoding cannot be found.

Definition at line 544 of file codecs.py.

References cgitb.lookup().

545 def getencoder(encoding):
546 
547  """ Lookup up the codec for the given encoding and return
548  its encoder function.
549 
550  Raises a LookupError in case the encoding cannot be found.
551 
552  """
553  return lookup(encoding)[0]
def codecs.getreader (   encoding)
Lookup up the codec for the given encoding and return
    its StreamReader class or factory function.

    Raises a LookupError in case the encoding cannot be found.

Definition at line 564 of file codecs.py.

References cgitb.lookup().

565 def getreader(encoding):
566 
567  """ Lookup up the codec for the given encoding and return
568  its StreamReader class or factory function.
569 
570  Raises a LookupError in case the encoding cannot be found.
571 
572  """
573  return lookup(encoding)[2]
def codecs.getwriter (   encoding)
Lookup up the codec for the given encoding and return
    its StreamWriter class or factory function.

    Raises a LookupError in case the encoding cannot be found.

Definition at line 574 of file codecs.py.

References cgitb.lookup().

575 def getwriter(encoding):
576 
577  """ Lookup up the codec for the given encoding and return
578  its StreamWriter class or factory function.
579 
580  Raises a LookupError in case the encoding cannot be found.
581 
582  """
583  return lookup(encoding)[3]
def codecs.make_encoding_map (   decoding_map)
Creates an encoding map from a decoding map.

    If a target mapping in the decoding map occurrs multiple
    times, then that target is mapped to None (undefined mapping),
    causing an exception when encountered by the charmap codec
    during translation.

    One example where this happens is cp875.py which decodes
    multiple character to \u001a.

Definition at line 599 of file codecs.py.

600 def make_encoding_map(decoding_map):
601 
602  """ Creates an encoding map from a decoding map.
603 
604  If a target mapping in the decoding map occurrs multiple
605  times, then that target is mapped to None (undefined mapping),
606  causing an exception when encountered by the charmap codec
607  during translation.
608 
609  One example where this happens is cp875.py which decodes
610  multiple character to \u001a.
611 
612  """
613  m = {}
614  for k,v in decoding_map.items():
615  if not m.has_key(v):
616  m[v] = k
617  else:
618  m[v] = None
619  return m
620 
621 # Tell modulefinder that using codecs probably needs the encodings
# package
def codecs.make_identity_dict (   rng)

Helpers for charmap-based codecs.

make_identity_dict(rng) -> dict

    Return a dictionary where elements of the rng sequence are
    mapped to themselves.

Definition at line 586 of file codecs.py.

587 def make_identity_dict(rng):
588 
589  """ make_identity_dict(rng) -> dict
590 
591  Return a dictionary where elements of the rng sequence are
592  mapped to themselves.
593 
594  """
595  res = {}
596  for i in rng:
597  res[i]=i
598  return res
def codecs.open (   filename,
  mode = 'rb',
  encoding = None,
  errors = 'strict',
  buffering = 1 
)
Open an encoded file using the given mode and return
    a wrapped version providing transparent encoding/decoding.

    Note: The wrapped version will only accept the object format
    defined by the codecs, i.e. Unicode objects for most builtin
    codecs. Output is also codec dependent and will usually by
    Unicode as well.

    Files are always opened in binary mode, even if no binary mode
    was specified. Thisis done to avoid data loss due to encodings
    using 8-bit values. The default file mode is 'rb' meaning to
    open the file in binary read mode.

    encoding specifies the encoding which is to be used for the
    the file.

    errors may be given to define the error handling. It defaults
    to 'strict' which causes ValueErrors to be raised in case an
    encoding error occurs.

    buffering has the same meaning as for the builtin open() API.
    It defaults to line buffered.

    The returned wrapped file object provides an extra attribute
    .encoding which allows querying the used encoding. This
    attribute is only available if an encoding was specified as
    parameter.

Definition at line 461 of file codecs.py.

References cgitb.lookup().

462 def open(filename, mode='rb', encoding=None, errors='strict', buffering=1):
463 
464  """ Open an encoded file using the given mode and return
465  a wrapped version providing transparent encoding/decoding.
466 
467  Note: The wrapped version will only accept the object format
468  defined by the codecs, i.e. Unicode objects for most builtin
469  codecs. Output is also codec dependent and will usually by
470  Unicode as well.
471 
472  Files are always opened in binary mode, even if no binary mode
473  was specified. Thisis done to avoid data loss due to encodings
474  using 8-bit values. The default file mode is 'rb' meaning to
475  open the file in binary read mode.
476 
477  encoding specifies the encoding which is to be used for the
478  the file.
479 
480  errors may be given to define the error handling. It defaults
481  to 'strict' which causes ValueErrors to be raised in case an
482  encoding error occurs.
483 
484  buffering has the same meaning as for the builtin open() API.
485  It defaults to line buffered.
486 
487  The returned wrapped file object provides an extra attribute
488  .encoding which allows querying the used encoding. This
489  attribute is only available if an encoding was specified as
490  parameter.
491 
492  """
493  if encoding is not None and \
494  'b' not in mode:
495  # Force opening of the file in binary mode
496  mode = mode + 'b'
497  file = __builtin__.open(filename, mode, buffering)
498  if encoding is None:
499  return file
500  (e, d, sr, sw) = lookup(encoding)
501  srw = StreamReaderWriter(file, sr, sw, errors)
502  # Add attributes to simplify introspection
503  srw.encoding = encoding
504  return srw

Variable Documentation

list __all__
Initial value:
1 = ["register", "lookup", "open", "EncodedFile", "BOM", "BOM_BE",
2  "BOM_LE", "BOM32_BE", "BOM32_LE", "BOM64_BE", "BOM64_LE"]

Definition at line 20 of file codecs.py.

int _false = 0

Definition at line 622 of file codecs.py.

tuple BOM = struct.pack('=H', 0xFEFF)

Constants.

Definition at line 28 of file codecs.py.

string BOM64_BE = '\000\000\376\377'

Definition at line 40 of file codecs.py.

string BOM64_LE = '\377\376\000\000'

Definition at line 42 of file codecs.py.

string BOM_BE = '\376\377'

Definition at line 30 of file codecs.py.

string BOM_LE = '\377\376'

Definition at line 33 of file codecs.py.