Utility function to load messages from a file-like object to a queue
195245
def load_from_file(self, fp, sep='\n'):
        """"""
        n = 0
        body = ''
        l = fp.readline()
        while l:
            if l == sep:
                m = Message(self, body)
                self.write(m)
                n += 1
                print 'writing message %d' % n
                body = ''
            else:
                body = body + l
            l = fp.readline()
        return n
433475
def load(file):
    
    with open(file, 'r') as f:
        contents = f.read()
    lambder.load_events(contents)
1004679
def _on_msg(self, msg):
        """"""
        data = msg['content']['data']

        # If the message is a call invoke, run the function and send
        # the results.
        if 'callback' in data:
            guid = data['callback']
            callback = callback_registry[guid]
            args = data['arguments']
            args = [self.deserialize(a) for a in args]
            index = data['index']

            results = callback(*args)
            return self.serialize(self._send('return', index=index, results=results))

        # The message is not a call invoke, it must be an object
        # that is a response to a Python request.
        else:
            index = data['index']
            immutable = data['immutable']
            value = data['value']
            if index in self._callbacks:
                self._callbacks[index].resolve({
                    'immutable': immutable,
                    'value': value
                })
                del self._callbacks[index]
761986
def from_file_obj(cls, fp):
        
        log.debug("Parsing email from file object")
        try:
            fp.seek(0)
        except IOError:
            # When stdout is a TTY it's a character device
            # and it's not seekable, you cannot seek in a TTY.
            pass
        finally:
            s = fp.read()

        return cls.from_string(s)
635141
def queue(ctx, message):
    """"""
    if not valid_tweet(message):
        click.echo("Message is too long for twitter.")
        click.echo("Message: " + message)
        ctx.exit(2)

    if ctx.obj['DRYRUN']:
        click.echo("Message not queue due to dry-run mode.")
        ctx.exit(0)

    ctx.obj['TWEETLIST'].append(message)
201955
def load(cls, filename, encoding):
        """"""
        if encoding is None:
            encoding = cls.encoding

        with io.open(filename, 'r', encoding=encoding) as fd:
            source = fd.read()

        if cls.normalize_newlines:
            source = source.replace('\r\n', '\n').replace('\r', '\n')
        return cls.loads(source)
1040456
function loadMockFromFile (fileName, options) {
    // make sure options is object
    options = requireValidOptionalObject(options)
    // load data from file
    var fileData = fs.readFileSync(fileName, 'utf8')
    // split lines - each line should be valid JSON object
    var lines = fileData.split('\n')
    // load each line
    _.each(lines, (line, lineNum) => {
        // skip empty lines
        if (line === '') {
            return
        }
        // attempt to parse line
        try {
            var mockData = JSON.parse(line)
        }
        catch (ex) {
            // throw error unless ignore option is set
            if (options.ignoreMockDataErrors) {
                return
            }
            else {
                // get line number starting at 1 instead of 0
                lineNum = parseInt(lineNum) + 1
                // throw error
                throw new Error('immutable-automock: JSON parse error '+ex.message+' '+fileName+':'+lineNum)
            }
        }
        // load mock data
        loadMock(mockData, options)
    })
}
50335
def from_file(cls, fn, *args, **kwargs):
        
        return AmiraHeader(get_parsed_data(fn, *args, **kwargs))
1202099
def load_messages(self, directory, catalogue):
        
        if not os.path.isdir(directory):
            raise ValueError("{0} is not a directory".format(directory))

        for format, loader in list(self.loaders.items()):
            extension = "{0}.{1}".format(catalogue.locale, format)
            files = find_files(directory, "*.{0}".format(extension))
            for file in files:
                domain = file.split("/")[-1][:-1 * len(extension) - 1]
                catalogue.add_catalogue(
                    loader.load(
                        file,
                        catalogue.locale,
                        domain))
742206
def queue(self, queue, message, params={}, uids=[]):
        
        d = {
            'id': uuid.uuid1().get_hex(),
            'version': 1,
            'message': message,
            'params': params
        }

        if uids:
            for uid in uids:
                yield self.client.lpush('rhumba.dq.%s.%s' % (
                    uid, queue), json.dumps(d))
        else:
            yield self.client.lpush('rhumba.q.%s' % queue, json.dumps(d))

        defer.returnValue(d['id'])
1363048
def msg(message, *args, **kwargs):
    """"""
    global log_file
    if log_file is None:
        log_file = sys.stderr
    if long_msg:
        file_name, line = caller_trace()
        file_name, file_type = os.path.splitext(file_name)
        if file_name.endswith('/__init__'):
            file_name = os.path.basename(os.path.dirname(file_name))
        elif file_name.endswith('/__main__'):
            file_name = "(-m) {0}".format(
                os.path.basename(os.path.dirname(file_name)))
        else:
            file_name = os.path.basename(file_name)
        head = '{0}{1} ({2}): '.format(file_name, file_type, line)
    else:
        head = '[SERVER] '
    out = StringIO()
    for line in message.format(*args, **kwargs).split('\n'):
        out.write('{0}{1}\n'.format(head, line))
    out.flush()
    out.seek(0)
    if _msg_stderr:
        sys.stderr.write(out.read())
        sys.stderr.flush()
    else:
        log_file.write(out.read())
        log_file.flush()
    out.close()
621793
def receive_messages_from_queue(self, wait_time=15, num_messages=1):
        

        return self.queue.receive_messages(MaxNumberOfMessages=num_messages,
                                           WaitTimeSeconds=wait_time)
1213103
function( status ) {
                var len = this._queue.length,
                    i, file;
    
                status = status || STATUS.QUEUED;
    
                for ( i = 0; i < len; i++ ) {
                    file = this._queue[ i ];
    
                    if ( status === file.getStatus() ) {
                        return file;
                    }
                }
    
                return null;
            }
1339072
function loadJSON (file, callback) {
  loadText(file, function (err, data) {
    if (err) {
      callback(err, null)
    } else {
      var json = null
      try {
        json = JSON.parse(data)
      } catch (e) {
        return callback(e, null)
      }
      callback(null, json)
    }
  })
}
634791
def getMessage(self, message):
        '''
        
        '''
        if message.filename != self._filename:
            raise RuntimeError(
                'Message filename ({:}) does not match batch filename ({:}).'
                .format(message.filename, self._filename))
        self._file.seek(message.offset)
        self._logger.debug(
            'Retrieved message offset={:}, size={:}'
            .format(message.offset, message.size))
        return self._file.read(message.size)
635618
def _load_file(self, log_file, message_name_filter_list):
        
        if isinstance(log_file, str):
            self._file_handle = open(log_file, "rb")
        else:
            self._file_handle = log_file

        # parse the whole file
        self._read_file_header()
        self._last_timestamp = self._start_timestamp
        self._read_file_definitions()

        if self.has_data_appended and len(self._appended_offsets) > 0:
            if self._debug:
                print('This file has data appended')
            for offset in self._appended_offsets:
                self._read_file_data(message_name_filter_list, read_until=offset)
                self._file_handle.seek(offset)

        # read the whole file, or the rest if data appended
        self._read_file_data(message_name_filter_list)

        self._file_handle.close()
        del self._file_handle
777371
def _load_from_file(self, filename):
    """"""
    if not tf.gfile.Exists(filename):
      raise ValueError("File %s not found" % filename)
    with tf.gfile.Open(filename) as f:
      self._load_from_file_object(f)