Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6218393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:36:07+00:00 2026-05-24T07:36:07+00:00

This code is copy from http://code.google.com/p/closure-library/source/browse/trunk/closure/bin/build/source.py The Source class’s __str __method referred self._path Is

  • 0

This code is copy from http://code.google.com/p/closure-library/source/browse/trunk/closure/bin/build/source.py

The Source class’s __str
__method referred self._path

Is it a special property for self?

Cuz, i couldn’t find the place define this variable at Source Class

import re

_BASE_REGEX_STRING = '^\s*goog\.%s\(\s*[\'"](.+)[\'"]\s*\)'
_PROVIDE_REGEX = re.compile(_BASE_REGEX_STRING % 'provide')
_REQUIRES_REGEX = re.compile(_BASE_REGEX_STRING % 'require')

# This line identifies base.js and should match the line in that file.
_GOOG_BASE_LINE = (
    'var goog = goog || {}; // Identifies this file as the Closure base.')


class Source(object):
  """Scans a JavaScript source for its provided and required namespaces."""

  def __init__(self, source):
    """Initialize a source.

    Args:
      source: str, The JavaScript source.
    """

    self.provides = set()
    self.requires = set()

    self._source = source
    self._ScanSource()

  def __str__(self):
    return 'Source %s' % self._path #!!!!!! what is self_path !!!!

  def GetSource(self):
    """Get the source as a string."""
    return self._source

  def _ScanSource(self):
    """Fill in provides and requires by scanning the source."""

    # TODO: Strip source comments first, as these might be in a comment
    # block.  RegExes can be borrowed from other projects.
    source = self.GetSource()

    source_lines = source.splitlines()
    for line in source_lines:
      match = _PROVIDE_REGEX.match(line)
      if match:
        self.provides.add(match.group(1))
      match = _REQUIRES_REGEX.match(line)
      if match:
        self.requires.add(match.group(1))

    # Closure's base file implicitly provides 'goog'.
    for line in source_lines:
      if line == _GOOG_BASE_LINE:
        if len(self.provides) or len(self.requires):
          raise Exception(
              'Base files should not provide or require namespaces.')
        self.provides.add('goog')


def GetFileContents(path):
  """Get a file's contents as a string.

  Args:
    path: str, Path to file.

  Returns:
    str, Contents of file.

  Raises:
    IOError: An error occurred opening or reading the file.

  """
  fileobj = open(path)
  try:
    return fileobj.read()
  finally:
    fileobj.close()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:36:08+00:00Added an answer on May 24, 2026 at 7:36 am

    No, _path is just an attribute that may or me not be set on an object like any other attribute. The leading underscore simply means that the author felt it was an internal detail of the object and didn’t want it regarded as part of the public interface.

    In this particular case, unless something is setting the attribute from outside that source file, it looks like it’s simply a mistake. It won’t do any harm unless anyone ever tries to call str() on a Source object and probably nobody ever does.

    BTW, you seem to be thinking there is something special about self. The name self isn’t special in any way: it’s a convention to use this name for the first parameter of a method, but it is just a name like any other that refers to the object being processed. So if you could access self._path without causing an error you could access it equally well through any other name for the object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've downloaded the JSON framework DMG from http://code.google.com/p/json-framework/downloads/list . I followed Option 3 here:
Quote from: http://msdn.microsoft.com/en-us/library/aa645739(VS.71).aspx "Invoking an event can only be done from within the class
Many beginning programmers write code like this: sub copy_file ($$) { my $from =
This code is from Prototype.js . I've looked at probably 20 different tutorials, and
I'd like to select the image source url from html code using javascript regexp.
Here's my code for my Facebook share link: <a href=<%= HttpUtility.UrlPathEncode(http://www.facebook.com/sharer.php?u=http://www.apoads.com+ Request.Url.PathAndQuery) %> title=Share
This code in JS gives me a popup saying i think null is a
this code always returns 0 in PHP 5.2.5 for microseconds: <?php $dt = new
This code works (C# 3) double d; if(d == (double)(int)d) ...; Is there a
This code always works, even in different browsers: function fooCheck() { alert(internalFoo()); // We

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.