selenium
This commit is contained in:
138
node_modules/plist/lib/build.js
generated
vendored
Normal file
138
node_modules/plist/lib/build.js
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var base64 = require('base64-js');
|
||||
var xmlbuilder = require('xmlbuilder');
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
*/
|
||||
|
||||
exports.build = build;
|
||||
|
||||
/**
|
||||
* Accepts a `Date` instance and returns an ISO date string.
|
||||
*
|
||||
* @param {Date} d - Date instance to serialize
|
||||
* @returns {String} ISO date string representation of `d`
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function ISODateString(d){
|
||||
function pad(n){
|
||||
return n < 10 ? '0' + n : n;
|
||||
}
|
||||
return d.getUTCFullYear()+'-'
|
||||
+ pad(d.getUTCMonth()+1)+'-'
|
||||
+ pad(d.getUTCDate())+'T'
|
||||
+ pad(d.getUTCHours())+':'
|
||||
+ pad(d.getUTCMinutes())+':'
|
||||
+ pad(d.getUTCSeconds())+'Z';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the internal "type" of `obj` via the
|
||||
* `Object.prototype.toString()` trick.
|
||||
*
|
||||
* @param {Mixed} obj - any value
|
||||
* @returns {String} the internal "type" name
|
||||
* @api private
|
||||
*/
|
||||
|
||||
var toString = Object.prototype.toString;
|
||||
function type (obj) {
|
||||
var m = toString.call(obj).match(/\[object (.*)\]/);
|
||||
return m ? m[1] : m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an XML plist string from the input object `obj`.
|
||||
*
|
||||
* @param {Object} obj - the object to convert
|
||||
* @param {Object} [opts] - optional options object
|
||||
* @returns {String} converted plist XML string
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function build (obj, opts) {
|
||||
var XMLHDR = {
|
||||
version: '1.0',
|
||||
encoding: 'UTF-8'
|
||||
};
|
||||
|
||||
var XMLDTD = {
|
||||
pubid: '-//Apple//DTD PLIST 1.0//EN',
|
||||
sysid: 'http://www.apple.com/DTDs/PropertyList-1.0.dtd'
|
||||
};
|
||||
|
||||
var doc = xmlbuilder.create('plist');
|
||||
|
||||
doc.dec(XMLHDR.version, XMLHDR.encoding, XMLHDR.standalone);
|
||||
doc.dtd(XMLDTD.pubid, XMLDTD.sysid);
|
||||
doc.att('version', '1.0');
|
||||
|
||||
walk_obj(obj, doc);
|
||||
|
||||
if (!opts) opts = {};
|
||||
// default `pretty` to `true`
|
||||
opts.pretty = opts.pretty !== false;
|
||||
return doc.end(opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* depth first, recursive traversal of a javascript object. when complete,
|
||||
* next_child contains a reference to the build XML object.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function walk_obj(next, next_child) {
|
||||
var tag_type, i, prop;
|
||||
var name = type(next);
|
||||
|
||||
if ('Undefined' == name) {
|
||||
return;
|
||||
} else if (Array.isArray(next)) {
|
||||
next_child = next_child.ele('array');
|
||||
for (i = 0; i < next.length; i++) {
|
||||
walk_obj(next[i], next_child);
|
||||
}
|
||||
|
||||
} else if (Buffer.isBuffer(next)) {
|
||||
next_child.ele('data').raw(next.toString('base64'));
|
||||
|
||||
} else if ('Object' == name) {
|
||||
next_child = next_child.ele('dict');
|
||||
for (prop in next) {
|
||||
if (next.hasOwnProperty(prop)) {
|
||||
next_child.ele('key').txt(prop);
|
||||
walk_obj(next[prop], next_child);
|
||||
}
|
||||
}
|
||||
|
||||
} else if ('Number' == name) {
|
||||
// detect if this is an integer or real
|
||||
// TODO: add an ability to force one way or another via a "cast"
|
||||
tag_type = (next % 1 === 0) ? 'integer' : 'real';
|
||||
next_child.ele(tag_type).txt(next.toString());
|
||||
|
||||
} else if ('Date' == name) {
|
||||
next_child.ele('date').txt(ISODateString(new Date(next)));
|
||||
|
||||
} else if ('Boolean' == name) {
|
||||
next_child.ele(next ? 'true' : 'false');
|
||||
|
||||
} else if ('String' == name) {
|
||||
next_child.ele('string').txt(next);
|
||||
|
||||
} else if ('ArrayBuffer' == name) {
|
||||
next_child.ele('data').raw(base64.fromByteArray(next));
|
||||
|
||||
} else if (next && next.buffer && 'ArrayBuffer' == type(next.buffer)) {
|
||||
// a typed array
|
||||
next_child.ele('data').raw(base64.fromByteArray(new Uint8Array(next.buffer), next_child));
|
||||
|
||||
}
|
||||
}
|
||||
49
node_modules/plist/lib/node.js
generated
vendored
Normal file
49
node_modules/plist/lib/node.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var fs = require('fs');
|
||||
var parse = require('./parse');
|
||||
var deprecate = require('util-deprecate');
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
*/
|
||||
|
||||
exports.parseFile = deprecate(parseFile, '`parseFile()` is deprecated. ' +
|
||||
'Use `parseString()` instead.');
|
||||
exports.parseFileSync = deprecate(parseFileSync, '`parseFileSync()` is deprecated. ' +
|
||||
'Use `parseStringSync()` instead.');
|
||||
|
||||
/**
|
||||
* Parses file `filename` as a .plist file.
|
||||
* Invokes `fn` callback function when done.
|
||||
*
|
||||
* @param {String} filename - name of the file to read
|
||||
* @param {Function} fn - callback function
|
||||
* @api public
|
||||
* @deprecated use parseString() instead
|
||||
*/
|
||||
|
||||
function parseFile (filename, fn) {
|
||||
fs.readFile(filename, { encoding: 'utf8' }, onread);
|
||||
function onread (err, inxml) {
|
||||
if (err) return fn(err);
|
||||
parse.parseString(inxml, fn);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses file `filename` as a .plist file.
|
||||
* Returns a when done.
|
||||
*
|
||||
* @param {String} filename - name of the file to read
|
||||
* @param {Function} fn - callback function
|
||||
* @api public
|
||||
* @deprecated use parseStringSync() instead
|
||||
*/
|
||||
|
||||
function parseFileSync (filename) {
|
||||
var inxml = fs.readFileSync(filename, 'utf8');
|
||||
return parse.parseStringSync(inxml);
|
||||
}
|
||||
200
node_modules/plist/lib/parse.js
generated
vendored
Normal file
200
node_modules/plist/lib/parse.js
generated
vendored
Normal file
@@ -0,0 +1,200 @@
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var deprecate = require('util-deprecate');
|
||||
var DOMParser = require('xmldom').DOMParser;
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
*/
|
||||
|
||||
exports.parse = parse;
|
||||
exports.parseString = deprecate(parseString, '`parseString()` is deprecated. ' +
|
||||
'It\'s not actually async. Use `parse()` instead.');
|
||||
exports.parseStringSync = deprecate(parseStringSync, '`parseStringSync()` is ' +
|
||||
'deprecated. Use `parse()` instead.');
|
||||
|
||||
/**
|
||||
* We ignore raw text (usually whitespace), <!-- xml comments -->,
|
||||
* and raw CDATA nodes.
|
||||
*
|
||||
* @param {Element} node
|
||||
* @returns {Boolean}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function shouldIgnoreNode (node) {
|
||||
return node.nodeType === 3 // text
|
||||
|| node.nodeType === 8 // comment
|
||||
|| node.nodeType === 4; // cdata
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses a Plist XML string. Returns an Object.
|
||||
*
|
||||
* @param {String} xml - the XML String to decode
|
||||
* @returns {Mixed} the decoded value from the Plist XML
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function parse (xml) {
|
||||
var doc = new DOMParser().parseFromString(xml);
|
||||
if (doc.documentElement.nodeName !== 'plist') {
|
||||
throw new Error('malformed document. First element should be <plist>');
|
||||
}
|
||||
var plist = parsePlistXML(doc.documentElement);
|
||||
|
||||
// the root <plist> node gets interpreted as an Array,
|
||||
// so pull out the inner data first
|
||||
if (plist.length == 1) plist = plist[0];
|
||||
|
||||
return plist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a Plist XML string. Returns an Object. Takes a `callback` function.
|
||||
*
|
||||
* @param {String} xml - the XML String to decode
|
||||
* @param {Function} callback - callback function
|
||||
* @returns {Mixed} the decoded value from the Plist XML
|
||||
* @api public
|
||||
* @deprecated not actually async. use parse() instead
|
||||
*/
|
||||
|
||||
function parseString (xml, callback) {
|
||||
var doc, error, plist;
|
||||
try {
|
||||
doc = new DOMParser().parseFromString(xml);
|
||||
plist = parsePlistXML(doc.documentElement);
|
||||
} catch(e) {
|
||||
error = e;
|
||||
}
|
||||
callback(error, plist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a Plist XML string. Returns an Object.
|
||||
*
|
||||
* @param {String} xml - the XML String to decode
|
||||
* @param {Function} callback - callback function
|
||||
* @returns {Mixed} the decoded value from the Plist XML
|
||||
* @api public
|
||||
* @deprecated use parse() instead
|
||||
*/
|
||||
|
||||
function parseStringSync (xml) {
|
||||
var doc = new DOMParser().parseFromString(xml);
|
||||
var plist;
|
||||
if (doc.documentElement.nodeName !== 'plist') {
|
||||
throw new Error('malformed document. First element should be <plist>');
|
||||
}
|
||||
plist = parsePlistXML(doc.documentElement);
|
||||
|
||||
// if the plist is an array with 1 element, pull it out of the array
|
||||
if (plist.length == 1) {
|
||||
plist = plist[0];
|
||||
}
|
||||
return plist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an XML based plist document into a JSON representation.
|
||||
*
|
||||
* @param {Object} xml_node - current XML node in the plist
|
||||
* @returns {Mixed} built up JSON object
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function parsePlistXML (node) {
|
||||
var i, new_obj, key, val, new_arr, res, d;
|
||||
|
||||
if (!node)
|
||||
return null;
|
||||
|
||||
if (node.nodeName === 'plist') {
|
||||
new_arr = [];
|
||||
for (i=0; i < node.childNodes.length; i++) {
|
||||
// ignore comment nodes (text)
|
||||
if (!shouldIgnoreNode(node.childNodes[i])) {
|
||||
new_arr.push( parsePlistXML(node.childNodes[i]));
|
||||
}
|
||||
}
|
||||
return new_arr;
|
||||
|
||||
} else if (node.nodeName === 'dict') {
|
||||
new_obj = {};
|
||||
key = null;
|
||||
for (i=0; i < node.childNodes.length; i++) {
|
||||
// ignore comment nodes (text)
|
||||
if (!shouldIgnoreNode(node.childNodes[i])) {
|
||||
if (key === null) {
|
||||
key = parsePlistXML(node.childNodes[i]);
|
||||
} else {
|
||||
new_obj[key] = parsePlistXML(node.childNodes[i]);
|
||||
key = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new_obj;
|
||||
|
||||
} else if (node.nodeName === 'array') {
|
||||
new_arr = [];
|
||||
for (i=0; i < node.childNodes.length; i++) {
|
||||
// ignore comment nodes (text)
|
||||
if (!shouldIgnoreNode(node.childNodes[i])) {
|
||||
res = parsePlistXML(node.childNodes[i]);
|
||||
if (null != res) new_arr.push(res);
|
||||
}
|
||||
}
|
||||
return new_arr;
|
||||
|
||||
} else if (node.nodeName === '#text') {
|
||||
// TODO: what should we do with text types? (CDATA sections)
|
||||
|
||||
} else if (node.nodeName === 'key') {
|
||||
return node.childNodes[0].nodeValue;
|
||||
|
||||
} else if (node.nodeName === 'string') {
|
||||
res = '';
|
||||
for (d=0; d < node.childNodes.length; d++) {
|
||||
res += node.childNodes[d].nodeValue;
|
||||
}
|
||||
return res;
|
||||
|
||||
} else if (node.nodeName === 'integer') {
|
||||
// parse as base 10 integer
|
||||
return parseInt(node.childNodes[0].nodeValue, 10);
|
||||
|
||||
} else if (node.nodeName === 'real') {
|
||||
res = '';
|
||||
for (d=0; d < node.childNodes.length; d++) {
|
||||
if (node.childNodes[d].nodeType === 3) {
|
||||
res += node.childNodes[d].nodeValue;
|
||||
}
|
||||
}
|
||||
return parseFloat(res);
|
||||
|
||||
} else if (node.nodeName === 'data') {
|
||||
res = '';
|
||||
for (d=0; d < node.childNodes.length; d++) {
|
||||
if (node.childNodes[d].nodeType === 3) {
|
||||
res += node.childNodes[d].nodeValue.replace(/\s+/g, '');
|
||||
}
|
||||
}
|
||||
|
||||
// decode base64 data to a Buffer instance
|
||||
return new Buffer(res, 'base64');
|
||||
|
||||
} else if (node.nodeName === 'date') {
|
||||
return new Date(node.childNodes[0].nodeValue);
|
||||
|
||||
} else if (node.nodeName === 'true') {
|
||||
return true;
|
||||
|
||||
} else if (node.nodeName === 'false') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
23
node_modules/plist/lib/plist.js
generated
vendored
Normal file
23
node_modules/plist/lib/plist.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
var i;
|
||||
|
||||
/**
|
||||
* Parser functions.
|
||||
*/
|
||||
|
||||
var parserFunctions = require('./parse');
|
||||
for (i in parserFunctions) exports[i] = parserFunctions[i];
|
||||
|
||||
/**
|
||||
* Builder functions.
|
||||
*/
|
||||
|
||||
var builderFunctions = require('./build');
|
||||
for (i in builderFunctions) exports[i] = builderFunctions[i];
|
||||
|
||||
/**
|
||||
* Add Node.js-specific functions (they're deprecated…).
|
||||
*/
|
||||
|
||||
var nodeFunctions = require('./node');
|
||||
for (i in nodeFunctions) exports[i] = nodeFunctions[i];
|
||||
Reference in New Issue
Block a user