@imports(['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'])<EOL>def load_item(inbox, type="<STR_LIT:string>", remove=True, buffer=None):
is_file, is_fifo, is_socket = False, False, False<EOL>file = inbox[<NUM_LIT:0>]<EOL>try:<EOL><INDENT>file_type = file[<NUM_LIT:0>]<EOL><DEDENT>except:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if file_type == "<STR_LIT:file>":<EOL><INDENT>is_file = os.path.exists(file[<NUM_LIT:1>])<EOL><DEDENT>elif file_type == "<STR_LIT>":<EOL><INDENT>is_fifo = stat.S_ISFIFO(os.stat(file[<NUM_LIT:1>]).st_mode)<EOL><DEDENT>elif file_type == "<STR_LIT>":<EOL><INDENT>is_socket = True<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % file_type)<EOL><DEDENT>if (is_fifo or is_socket) and (type == '<STR_LIT>'):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (is_fifo or is_socket) and not remove:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>start = <NUM_LIT:0><EOL>if is_fifo or is_file:<EOL><INDENT>stop = os.stat(file[<NUM_LIT:1>]).st_size - <NUM_LIT:1><EOL>fd = os.open(file[<NUM_LIT:1>], os.O_RDONLY)<EOL>BUFFER = (buffer or PAPY_DEFAULTS['<STR_LIT>'])<EOL><DEDENT>elif is_socket:<EOL><INDENT>host, port = socket.gethostbyname(file[<NUM_LIT:1>]), file[<NUM_LIT:2>]<EOL>sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<EOL>sock.connect((host, port))<EOL>stop = -<NUM_LIT:1><EOL>fd = sock.fileno()<EOL>BUFFER = (buffer or PAPY_DEFAULTS['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % (repr(inbox)))<EOL><DEDENT>if type == '<STR_LIT>':<EOL><INDENT>offset = start - (start % (getattr(mmap, '<STR_LIT>', None)or getattr(mmap, '<STR_LIT>')))<EOL>start = start - offset<EOL>stop = stop - offset + <NUM_LIT:1><EOL>try:<EOL><INDENT>data = mmap.mmap(fd, stop, access=mmap.ACCESS_READ, offset=offset)<EOL><DEDENT>except TypeError:<EOL><INDENT>data = mmap.mmap(fd, stop, access=mmap.ACCESS_READ)<EOL><DEDENT>data.seek(start)<EOL><DEDENT>elif type == '<STR_LIT:string>':<EOL><INDENT>data = []<EOL>if stop == -<NUM_LIT:1>:<EOL><INDENT>while True:<EOL><INDENT>buffer_ = os.read(fd, BUFFER)<EOL>if not buffer_:<EOL><INDENT>break<EOL><DEDENT>data.append(buffer_)<EOL><DEDENT>data = "<STR_LIT>".join(data)<EOL><DEDENT>else:<EOL><INDENT>os.lseek(fd, start, <NUM_LIT:0>)<EOL>data = os.read(fd, stop - start + <NUM_LIT:1>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>' % type)<EOL><DEDENT>if remove:<EOL><INDENT>if is_socket:<EOL><INDENT>sock.close()<EOL><DEDENT>else:<EOL><INDENT>os.close(fd)<EOL>os.unlink(file[<NUM_LIT:1>])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>os.close(fd)<EOL><DEDENT>return data<EOL>
Loads data from a file. Determines the file type automatically ``"file"``,
``"fifo"``, ``"socket"``, but allows to specify the representation type 
``"string"`` or ``"mmap"`` for memory mapped access to the file. Returns 
the  loaded item as a ``str`` or ``mmap`` object. Internally creates an item
from a ``file``.

Arguments:

  - type(``"string"`` or ``"mmap"``) [default: ``"string"``] Determines the
    type of ``object`` the worker returns i.e. the ``file`` is read as a 
    string or a memmory map. FIFOs cannot be memory mapped. 
  - remove(``bool``) [default: ``True``] Should the file be removed from the
    filesystem? This is mandatory for FIFOs and sockets. Only Files can be 
    used to store data persistantly.