/* Meta function to define new socket/context options.
762011
function defineOption(id, type, names, {read = true, write = true, on = this, values = null} = {}) {
  let get, set

  if (read) {
    if (values) {
      get = function get() { return values[this[`get${type}Option`](id)] }
    } else {
      get = function get() { return this[`get${type}Option`](id) }
    }
  }

  if (write) {
    if (values) {
      set = function set(val) { this[`set${type}Option`](id, values.indexOf(val)) }
    } else {
      set = function set(val) { this[`set${type}Option`](id, val) }
    }
  }

  if (!Array.isArray(on)) on = [on]

  for (const name of names) {
    for (const target of on) {
      Object.defineProperty(target.prototype, name, {get, set})
    }
  }
}
849678
function (options) {

      var clientShell = this,
      context = {},
      // Default settings.
      defaultSettings = {
        namespace: 'shotgun',
        debug: false
      };

      // Override default settings with supplied options.
      var settings = clientShell.settings = extend(true, {}, defaultSettings, options);

      // Instruct socket.io to connect to the server.
      var socket = clientShell.socket = io.connect('/' + settings.namespace);

      // Proxy any listeners onto the socket itself.
      clientShell.on = function () {
        socket.on.apply(socket, arguments);
        return clientShell;
      };

      // Proxy any emit calls onto the socket itself.
      clientShell.emit = function () {
        socket.emit.apply(socket, arguments);
        return clientShell;
      };

      function getCookies() {
        var cookies = {};
        if (document.cookie.length > 0)
          document.cookie.split(';').forEach(function (cookie) {
            var components = cookie.split('='),
            name = components[0].trim(),
            value = components[1];
            if (name.indexOf(settings.namespace + '-') === 0) {
              name = name.replace(settings.namespace + '-', '');
              cookies[name] = decodeURIComponent(value);
            }
          });
          return cookies;
      }

      clientShell
      // Save context when it changes.
      .on('contextChanged', function (contextData) {
        context = contextData;
      })
      // Create a function for setting cookies in the browser.
      .on('setCookie', function (name, value, days) {
        var expiration = new Date();
        expiration.setDate(expiration.getDate() + days);
        value = encodeURIComponent(value) + ((days === null) ? "" : ";expires=" + expiration.toUTCString());
        document.cookie = settings.namespace + '-' + name + "=" + value;
      })
      .on('getCookie', function (name, callback) {
        // Create a cookies property on the context and fill it with all the cookies for this shell.
        var cookies = getCookies();
        callback(cookies[name]);
      })
      .on('getAllCookies', function (callback) {
        var cookies = getCookies();
        callback(cookies);
      });

      // Create an execute function that looks similar to the shotgun shell execute function for ease of use.
      clientShell.execute = function (cmdStr, contextOverride, options) {
        // If a context was passed in then override the stored context with it.
        if (contextOverride) context = contextOverride;
        socket.emit('execute', cmdStr, context, options);
        return clientShell;
      };

      return clientShell;
    }
1094666
function connectionListDirective($scope, Clients, Socket) {

        var ctrl = this;
        ctrl.connections = [];

        ctrl.update = function (data) {
            ctrl.connections = data;
            $scope.$digest();
        };

        // Always try to retreive the sockets first time.
        Socket.getData("clients").then(function (data) {
            ctrl.connections = data;
        });

        // Listen to events to update the list on the fly
        Socket.on("ui:connections:update", ctrl.update);

        $scope.$on("$destroy", function () {
            Socket.off("ui:connections:update", ctrl.update);
        });

        ctrl.highlight = function (connection) {
            Clients.highlight(connection);
        };
    }
204048
def set_meta(request):
    
    context_extras = {}
    if not request.is_ajax() and hasattr(request, 'upy_context') and request.upy_context['PAGE']:
        context_extras['PAGE'] = request.upy_context['PAGE']
        context_extras['NODE'] = request.upy_context['NODE']
    return context_extras
698554
function () {
                /*  determine parameters  */
                var params = $cs.params("socket", arguments, {
                    name:   {         def: "default"  },
                    scope:  {         def: null       },
                    ctx:    { pos: 0, req: true       },
                    plug:   { pos: 1, def: null       }, /*  removed "req: true"  */
                    unplug: { pos: 2, def: null       }, /*  removed "req: true"  */
                    spool:  {         def: null       }
                });

                /*  provide specialized socket "plug" functionality  */
                if (params.plug === null) {
                    params.plug = function (el /*, comp */) {
                        /*  on-the-fly get the HTML element from jQuery/Vue object  */
                        if (isjQuery(el))
                            el = el.get(0);
                        else if (isVue(el))
                            el = el.$el;

                        /*  append it to the DOM tree (the jQuery or plain way)  */
                        if (isjQuery(this))
                            this.append(el);
                        else
                            this.appendChild(el);
                    };
                }

                /*  provide specialized socket "unplug" functionality  */
                if (params.unplug === null) {
                    params.unplug = function (el /*, comp */) {
                        /*  remove it from the DOM tree (the jQuery way)  */
                        if (isjQuery(el))
                            el.detach();
                        else {
                            /*  on-the-fly get the HTML element from Vue object  */
                            if (isVue(el))
                                el = el.$el;

                            /*  remove it from the DOM tree (the plain way)  */
                            var parent = el.parentElement;
                            if (parent !== null)
                                parent.removeChild(el);
                        }
                    };
                }

                /*  pass-through execution to original/base method  */
                return this.base(params);
            }
164367
function NodeContext(msg, parent, nodeContext, serverName) {
    this.msgContext = new mustache.Context(msg, parent);
    this.nodeContext = nodeContext;
    this.serverName = serverName;
}
722109
function defineBuiltinVars(context) {
  // define salesforce package root objects
  for (var key in sf) {
    if (sf.hasOwnProperty(key) && !global[key]) {
      context[key] = sf[key];
    }
  }
  // expose salesforce package root as "$sf" in context.
  context.$sf = sf;

  // create default connection object
  var conn = new sf.Connection();

  for (var prop in conn) {
    if (prop.indexOf('_') === 0) { // ignore private
      continue;
    }
    if (_.isFunction(conn[prop])) {
      context[prop] = _.bind(conn[prop], conn);
    } else if (_.isObject(conn[prop])) {
      defineProp(context, conn, prop);
    }
  }

  // expose default connection as "$conn"
  context.$conn = conn;
}
891292
function SocketServices( options ){
	options = options || {};

	var self = this;

	this.logger = Logger.createLogger( 'socket', {'socket-services': VERSION}, options.logger );

	self.server = options.server || { };

	this.messageValidator = options.messageValidator || isCommunication;

	this.channel = options.channel || 'api';
	this.event = options.event || 'rester';

	self.logger.info('Will accepting communication on channel \'' + self.channel + '\' emitting to event \'' + self.event + '\'' );

	this.inflicter = new Inflicter( { logger: self.logger, idLength: options.idLength || 16 } );

	self.logger.info( 'Event system activated.' );
}
545463
function(id, msg, meta) {
        var socket = openSocketsById[id];
        if (socket) {
          return socket.write('0|' + msg + '|' + meta)
        } else {
          return false;
        }
      }
599607
def _register_socket(self):
        """"""
        _socket = socket.socket(*Socket.protocols[self.connection.proto])
        _socket.settimeout(self.timeout)

        # Reconfigure original socket options.
        if self.connection.sockopts:
            for sock_opt in self.connection.sockopts:
                level, option, value = sock_opt
                _socket.setsockopt(level, option, value)

        _socket.connect(self.connection.connect_to)
        return _socket
723211
function create(context) {
    const settings = Object.assign({}, defaults, context.options[0]);

    function check(setting, node, list, format) {
        const val = settings[setting];
        const lines = list.map(line);

        if ((isLongerThan(val, lines) || isAlways(val)) && hasDuplicates(lines)) {
            const message = messages.always[setting];
            const fix = (f) => f.replaceTextRange(node.range, format(node));
            context.report({ node, message, fix });
        }

        if (isNever(val) && hasMultiple(lines)) {
            const message = messages.never[setting];
            context.report({ node, message });
        }
    }

    return {
        CallExpression(node) {
            if (!isAmdCall(node) || node.arguments.length < 2) return;

            const args = withoutModuleId(node.arguments);
            const deps = args[0];
            const func = args[1];

            if (!isArrayExpr(deps) || !isFunctionExpr(func)) return;

            const indent = indentation(func);

            check("paths", deps, deps.elements, formatPaths(indent));
            check("names", func, func.params, formatNames(indent, context));
        }
    };
}
387129
def token_meta(opt):
    """"""
    meta = {
        'via': 'aomi',
        'operation': opt.operation,
        'hostname': socket.gethostname()
    }
    if 'USER' in os.environ:
        meta['unix_user'] = os.environ['USER']

    if opt.metadata:
        meta_bits = opt.metadata.split(',')
        for meta_bit in meta_bits:
            key, value = meta_bit.split('=')

        if key not in meta:
            meta[key] = value

    for key, value in meta.items():
        LOG.debug("Token metadata %s %s", key, value)

    return meta
135350
function metaToValue (meta) {
  const types = {
    value: () => meta.value,
    array: () => meta.members.map((member) => metaToValue(member)),
    buffer: () => bufferUtils.metaToBuffer(meta.value),
    promise: () => resolvePromise({ then: metaToValue(meta.then) }),
    error: () => metaToPlainObject(meta),
    date: () => new Date(meta.value),
    exception: () => { throw errorUtils.deserialize(meta.value) }
  }

  if (meta.type in types) {
    return types[meta.type]()
  } else {
    let ret
    if (remoteObjectCache.has(meta.id)) {
      v8Util.addRemoteObjectRef(contextId, meta.id)
      return remoteObjectCache.get(meta.id)
    }

    // A shadow class to represent the remote function object.
    if (meta.type === 'function') {
      const remoteFunction = function (...args) {
        let command
        if (this && this.constructor === remoteFunction) {
          command = 'ELECTRON_BROWSER_CONSTRUCTOR'
        } else {
          command = 'ELECTRON_BROWSER_FUNCTION_CALL'
        }
        const obj = ipcRendererInternal.sendSync(command, contextId, meta.id, wrapArgs(args))
        return metaToValue(obj)
      }
      ret = remoteFunction
    } else {
      ret = {}
    }

    setObjectMembers(ret, ret, meta.id, meta.members)
    setObjectPrototype(ret, ret, meta.id, meta.proto)
    Object.defineProperty(ret.constructor, 'name', { value: meta.name })

    // Track delegate obj's lifetime & tell browser to clean up when object is GCed.
    v8Util.setRemoteObjectFreer(ret, contextId, meta.id)
    v8Util.setHiddenValue(ret, 'atomId', meta.id)
    v8Util.addRemoteObjectRef(contextId, meta.id)
    remoteObjectCache.set(meta.id, ret)
    return ret
  }
}
1305128
def _set_up_context(cls):
        """"""
        cls.context = AttributeDict()
        cls.context.new_meta = {}
        cls.context.new_transitions = {}
        cls.context.new_methods = {}
258159
function Socket (options) {
    this.options = {
        port: 80
      , secure: false
      , document: 'document' in global ? document : false
      , resource: 'socket.io'
      , transports: io.transports
      , 'connect timeout': 10000
      , 'try multiple transports': true
      , 'reconnect': true
      , 'reconnection delay': 500
      , 'reconnection limit': Infinity
      , 'reopen delay': 3000
      , 'max reconnection attempts': 10
      , 'sync disconnect on unload': true
      , 'auto connect': true
      , 'flash policy port': 10843
    };

    io.util.merge(this.options, options);

    this.connected = false;
    this.open = false;
    this.connecting = false;
    this.reconnecting = false;
    this.namespaces = {};
    this.buffer = [];
    this.doBuffer = false;

    if (this.options['sync disconnect on unload'] &&
        (!this.isXDomain() || io.util.ua.hasCORS)) {
      var self = this;

      io.util.on(global, 'unload', function () {
        self.disconnectSync();
      }, false);
    }

    if (this.options['auto connect']) {
      this.connect();
    }
}
169784
@Override
	public Context create(String name, Tree params, CallOptions.Options opts, PacketStream stream, Context parent) {

		// Generate ID
		String id = uid.nextUID();

		// Create new Context
		if (parent == null) {
			return new Context(serviceInvoker, eventbus, id, name, params, opts, stream);
		}

		// Merge meta block
		if (parent.params != null) {
			Tree parentMeta = parent.params.getMeta(false);
			if (parentMeta != null && !parentMeta.isEmpty()) {
				Tree currentMeta = params.getMeta(true);
				if (currentMeta.isEmpty()) {
					currentMeta.setObject(parentMeta.asObject());
				} else {
					currentMeta.copyFrom(parentMeta, false);
				}
			}
		}

		// Verify call level
		if (maxCallLevel > 0 && parent.level >= maxCallLevel) {
			throw new MaxCallLevelError(broker.getNodeID(), maxCallLevel);
		}

		// Create context (nested call)
		return new Context(id, name, params, opts, stream, parent);
	}
98018
protected function configureMasterSocket(): void
    {
        $class = $this->options['socket_master_class'];
        $options = $this->options['socket_master_options'];
        $this->socket = new $class($this->server->getUri(), $options);
    }