Exemple #1
0
def GetInjectScript(scripts):
  """Loads |scripts| from disk and returns a string of their content."""
  lines = []
  if scripts:
    for script in scripts.split(','):
      if os.path.exists(script):
        lines += open(script).read()
      elif util.resource_exists(script):
        lines += util.resource_string(script)
      else:
        raise HttpClientException('Script does not exist: %s', script)
  
  def MinifyScript(script):
    """Remove C-style comments and line breaks from script.
    Note: statements must be ';' terminated, and not depending on newline"""
    # Regex adapted from http://ostermiller.org/findcomment.html.
    MULTILINE_COMMENT_RE = re.compile(r'/\*.*?\*/', re.DOTALL | re.MULTILINE)
    SINGLELINE_COMMENT_RE = re.compile(r'//.*', re.MULTILINE)
    # Remove C-style comments from JS.
    script = re.sub(MULTILINE_COMMENT_RE, '', script)
    script = re.sub(SINGLELINE_COMMENT_RE, '', script)
    # Remove line breaks.
    script = script.translate(None, '\r\n')
    return script

  return MinifyScript(''.join(lines))
Exemple #2
0
def GetInjectScript(scripts):
    """Loads |scripts| from disk and returns a string of their content."""
    lines = []
    for script in scripts:
        if os.path.exists(script):
            lines += open(script).read()
        elif util.resource_exists(script):
            lines += util.resource_string(script)
        else:
            raise HttpClientException('Script does not exist: %s', script)
    return ''.join(lines)
Exemple #3
0
def GetInjectScript(scripts):
    """Loads |scripts| from disk and returns a string of their content."""
    lines = []
    for script in scripts:
        if os.path.exists(script):
            lines += open(script).read()
        elif util.resource_exists(script):
            lines += util.resource_string(script)
        else:
            raise HttpClientException("Script does not exist: %s", script)
    return "".join(lines)
Exemple #4
0
def GetInjectScript(scripts):
    """Loads |scripts| from disk and returns a string of their content."""
    lines = []
    if scripts:
        if not isinstance(scripts, list):
            scripts = scripts.split(',')
        for script in scripts:
            if os.path.exists(script):
                with open(script) as f:
                    lines.extend(f.read())
            elif util.resource_exists(script):
                lines.extend(util.resource_string(script))
            else:
                raise Exception('Script does not exist: %s', script)

    return jsmin.jsmin(''.join(lines), quote_chars="'\"`")
def GetInjectScript(scripts):
  """Loads |scripts| from disk and returns a string of their content."""
  lines = []
  if scripts:
    if not isinstance(scripts, list):
      scripts = scripts.split(',')
    for script in scripts:
      if os.path.exists(script):
        with open(script) as f:
          lines.extend(f.read())
      elif util.resource_exists(script):
        lines.extend(util.resource_string(script))
      else:
        raise Exception('Script does not exist: %s', script)

  return jsmin.jsmin(''.join(lines), quote_chars="'\"`")
Exemple #6
0
def GetScriptInjector(scripts):
  """Loads |scripts| from disk and returns an injector of their content."""
  lines = []
  if scripts:
    if not isinstance(scripts, list):
      scripts = scripts.split(',')
    for script in scripts:
      if os.path.exists(script):
        with open(script) as f:
          lines.extend(f.read())
      elif util.resource_exists(script):
        lines.extend(util.resource_string(script))
      else:
        raise Exception('Script does not exist: %s', script)

  script_template = jsmin.jsmin(''.join(lines), quote_chars="'\"`")
  def injector(record_time):
    delta = record_time - datetime.datetime(1970, 1, 1)
    js_timestamp = \
        int(delta.total_seconds()) * 1000 + delta.microseconds / 1000
    return script_template.replace(TIME_SEED_MARKER, str(js_timestamp))
  return injector
def get_mock_requests():
  keepends = True
  return util.resource_string('mock-archive.txt').splitlines(keepends)
Exemple #8
0
def get_mock_requests():
    keepends = True
    return util.resource_string('mock-archive.txt').splitlines(keepends)