Python string.lstrip() Examples
The following are 30
code examples of string.lstrip().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
string
, or try the search function
.
Example #1
Source File: service.py From service.subtitles.addic7ed with GNU General Public License v2.0 | 6 votes |
def search_filename(filename, languages): title, year = xbmc.getCleanMovieTitle(filename) log(__name__, "clean title: \"%s\" (%s)" % (title, year)) try: yearval = int(year) except ValueError: yearval = 0 if title and yearval > 1900: query_Film(title, year, item['3let_language'], filename) else: match = re.search(r'\WS(?P<season>\d\d)E(?P<episode>\d\d)', title, flags=re.IGNORECASE) if match is not None: tvshow = string.strip(title[:match.start('season')-1]) season = string.lstrip(match.group('season'), '0') episode = string.lstrip(match.group('episode'), '0') query_TvShow(tvshow, season, episode, item['3let_language'], filename) else: search_manual(filename, item['3let_language'], filename)
Example #2
Source File: inspect.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def cleandoc(doc): """Clean up indentation from docstrings. Any whitespace that can be uniformly removed from the second line onwards is removed.""" try: lines = string.split(string.expandtabs(doc), '\n') except UnicodeError: return None else: # Find minimum indentation of any non-blank lines after first line. margin = sys.maxint for line in lines[1:]: content = len(string.lstrip(line)) if content: indent = len(line) - content margin = min(margin, indent) # Remove indentation. if lines: lines[0] = lines[0].lstrip() if margin < sys.maxint: for i in range(1, len(lines)): lines[i] = lines[i][margin:] # Remove any trailing or leading blank lines. while lines and not lines[-1]: lines.pop() while lines and not lines[0]: lines.pop(0) return string.join(lines, '\n')
Example #3
Source File: inspect.py From ironpython2 with Apache License 2.0 | 5 votes |
def cleandoc(doc): """Clean up indentation from docstrings. Any whitespace that can be uniformly removed from the second line onwards is removed.""" try: lines = string.split(string.expandtabs(doc), '\n') except UnicodeError: return None else: # Find minimum indentation of any non-blank lines after first line. margin = sys.maxint for line in lines[1:]: content = len(string.lstrip(line)) if content: indent = len(line) - content margin = min(margin, indent) # Remove indentation. if lines: lines[0] = lines[0].lstrip() if margin < sys.maxint: for i in range(1, len(lines)): lines[i] = lines[i][margin:] # Remove any trailing or leading blank lines. while lines and not lines[-1]: lines.pop() while lines and not lines[0]: lines.pop(0) return string.join(lines, '\n')
Example #4
Source File: inspect.py From oss-ftp with MIT License | 5 votes |
def indentsize(line): """Return the indent size, in spaces, at the start of a line of text.""" expline = string.expandtabs(line) return len(expline) - len(string.lstrip(expline))
Example #5
Source File: zookeeper.py From incubator-retired-cotton with Apache License 2.0 | 5 votes |
def parse(url): """ Parse ZooKeeper URL. :param url: The URL in the form of "zk://username:password@servers/path". :return: Tuple (credential, servers, path). credential: Credential for authentication with "digest" scheme. Optional and default to None. servers: Compatible with Kazoo's 'hosts' argument. path: Optional and default to '/'. NOTE: This method doesn't validate the values in the returned tuple. """ index = string.find(url, "zk://") if index != 0: raise ValueError("Expecting 'zk://' at the beginning of the URL") url = string.lstrip(url, "zk://") try: servers, path = string.split(url, '/', 1) except ValueError: servers = url path = '' path = '/' + path try: credential, servers = string.split(servers, '@', 1) except ValueError: credential = None return credential, servers, path
Example #6
Source File: XbmImagePlugin.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def _accept(prefix): return string.lstrip(prefix)[:7] == "#define" ## # Image plugin for X11 bitmaps.
Example #7
Source File: inspect.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def indentsize(line): """Return the indent size, in spaces, at the start of a line of text.""" expline = string.expandtabs(line) return len(expline) - len(string.lstrip(expline))
Example #8
Source File: inspect.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def cleandoc(doc): """Clean up indentation from docstrings. Any whitespace that can be uniformly removed from the second line onwards is removed.""" try: lines = string.split(string.expandtabs(doc), '\n') except UnicodeError: return None else: # Find minimum indentation of any non-blank lines after first line. margin = sys.maxint for line in lines[1:]: content = len(string.lstrip(line)) if content: indent = len(line) - content margin = min(margin, indent) # Remove indentation. if lines: lines[0] = lines[0].lstrip() if margin < sys.maxint: for i in range(1, len(lines)): lines[i] = lines[i][margin:] # Remove any trailing or leading blank lines. while lines and not lines[-1]: lines.pop() while lines and not lines[0]: lines.pop(0) return string.join(lines, '\n')
Example #9
Source File: yaml.py From stdm with GNU General Public License v2.0 | 5 votes |
def readLine(self, line): #this is the inner loop self._lineNo = self._lineNo + 1 stripped = string.lstrip(line) if len(stripped) == 0: if self._mode == PLAIN: self.endPara() else: #preformatted, append it self._buf.append(line) elif line[0]=='.': # we have a command of some kind self.endPara() words = string.split(stripped[1:]) cmd, args = words[0], words[1:] #is it a parser method? if hasattr(self.__class__, cmd): #this was very bad; any type error in the method was hidden #we have to hack the traceback try: getattr(self,cmd)(*args) except TypeError, err: sys.stderr.write("Parser method: %s(*%s) %s at line %d\n" % (cmd, args, err, self._lineNo)) raise else: # assume it is a paragraph style - # becomes the formatter's problem self.endPara() #end the last one words = string.split(stripped, ' ', 1) assert len(words)==2, "Style %s but no data at line %d" % (words[0], self._lineNo) (styletag, data) = words self._style = styletag[1:] self._buf.append(data)
Example #10
Source File: inspect.py From medicare-demo with Apache License 2.0 | 5 votes |
def cleandoc(doc): """Clean up indentation from docstrings. Any whitespace that can be uniformly removed from the second line onwards is removed.""" try: lines = string.split(string.expandtabs(doc), '\n') except UnicodeError: return None else: # Find minimum indentation of any non-blank lines after first line. margin = sys.maxint for line in lines[1:]: content = len(string.lstrip(line)) if content: indent = len(line) - content margin = min(margin, indent) # Remove indentation. if lines: lines[0] = lines[0].lstrip() if margin < sys.maxint: for i in range(1, len(lines)): lines[i] = lines[i][margin:] # Remove any trailing or leading blank lines. while lines and not lines[-1]: lines.pop() while lines and not lines[0]: lines.pop(0) return string.join(lines, '\n')
Example #11
Source File: XbmImagePlugin.py From CNCGToolKit with MIT License | 5 votes |
def _accept(prefix): return string.lstrip(prefix)[:7] == "#define" ## # Image plugin for X11 bitmaps.
Example #12
Source File: Helpers.py From SimplyTemplate with GNU General Public License v2.0 | 5 votes |
def Reindent(s, numSpaces): # http://code.activestate.com/recipes/66055-changing-the-indentation-of-a-multi-line-string/ s = string.split(s, '\n') s = [(numSpaces * ' ') + string.lstrip(line) for line in s] s = string.join(s, '\n') return s
Example #13
Source File: _pydev_inspect.py From filmkodi with Apache License 2.0 | 5 votes |
def indentsize(line): """Return the indent size, in spaces, at the start of a line of text.""" expline = string.expandtabs(line) return len(expline) - len(string.lstrip(expline))
Example #14
Source File: _pydev_inspect.py From filmkodi with Apache License 2.0 | 5 votes |
def getdoc(object): """Get the documentation string for an object. All tabs are expanded to spaces. To clean up docstrings that are indented to line up with blocks of code, any whitespace than can be uniformly removed from the second line onwards is removed.""" try: doc = object.__doc__ except AttributeError: return None if not isinstance(doc, (str, unicode)): return None try: lines = string.split(string.expandtabs(doc), '\n') except UnicodeError: return None else: margin = None for line in lines[1:]: content = len(string.lstrip(line)) if not content: continue indent = len(line) - content if margin is None: margin = indent else: margin = min(margin, indent) if margin is not None: for i in range(1, len(lines)): lines[i] = lines[i][margin:] return string.join(lines, '\n')
Example #15
Source File: _pydev_inspect.py From filmkodi with Apache License 2.0 | 5 votes |
def getcomments(object): """Get lines of comments immediately preceding an object's source code.""" try: lines, lnum = findsource(object) except IOError: return None if ismodule(object): # Look for a comment block at the top of the file. start = 0 if lines and lines[0][:2] == '#!': start = 1 while start < len(lines) and string.strip(lines[start]) in ['', '#']: start = start + 1 if start < len(lines) and lines[start][:1] == '#': comments = [] end = start while end < len(lines) and lines[end][:1] == '#': comments.append(string.expandtabs(lines[end])) end = end + 1 return string.join(comments, '') # Look for a preceding block of comments at the same indentation. elif lnum > 0: indent = indentsize(lines[lnum]) end = lnum - 1 if end >= 0 and string.lstrip(lines[end])[:1] == '#' and \ indentsize(lines[end]) == indent: comments = [string.lstrip(string.expandtabs(lines[end]))] if end > 0: end = end - 1 comment = string.lstrip(string.expandtabs(lines[end])) while comment[:1] == '#' and indentsize(lines[end]) == indent: comments[:0] = [comment] end = end - 1 if end < 0: break comment = string.lstrip(string.expandtabs(lines[end])) while comments and string.strip(comments[0]) == '#': comments[:1] = [] while comments and string.strip(comments[-1]) == '#': comments[-1:] = [] return string.join(comments, '')
Example #16
Source File: inspect.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def indentsize(line): """Return the indent size, in spaces, at the start of a line of text.""" expline = string.expandtabs(line) return len(expline) - len(string.lstrip(expline))
Example #17
Source File: inspect.py From medicare-demo with Apache License 2.0 | 5 votes |
def indentsize(line): """Return the indent size, in spaces, at the start of a line of text.""" expline = string.expandtabs(line) return len(expline) - len(string.lstrip(expline))
Example #18
Source File: inspect.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def cleandoc(doc): """Clean up indentation from docstrings. Any whitespace that can be uniformly removed from the second line onwards is removed.""" try: lines = string.split(string.expandtabs(doc), '\n') except UnicodeError: return None else: # Find minimum indentation of any non-blank lines after first line. margin = sys.maxint for line in lines[1:]: content = len(string.lstrip(line)) if content: indent = len(line) - content margin = min(margin, indent) # Remove indentation. if lines: lines[0] = lines[0].lstrip() if margin < sys.maxint: for i in range(1, len(lines)): lines[i] = lines[i][margin:] # Remove any trailing or leading blank lines. while lines and not lines[-1]: lines.pop() while lines and not lines[0]: lines.pop(0) return string.join(lines, '\n')
Example #19
Source File: inspect.py From RevitBatchProcessor with GNU General Public License v3.0 | 5 votes |
def indentsize(line): """Return the indent size, in spaces, at the start of a line of text.""" expline = string.expandtabs(line) return len(expline) - len(string.lstrip(expline))
Example #20
Source File: inspect.py From RevitBatchProcessor with GNU General Public License v3.0 | 5 votes |
def cleandoc(doc): """Clean up indentation from docstrings. Any whitespace that can be uniformly removed from the second line onwards is removed.""" try: lines = string.split(string.expandtabs(doc), '\n') except UnicodeError: return None else: # Find minimum indentation of any non-blank lines after first line. margin = sys.maxint for line in lines[1:]: content = len(string.lstrip(line)) if content: indent = len(line) - content margin = min(margin, indent) # Remove indentation. if lines: lines[0] = lines[0].lstrip() if margin < sys.maxint: for i in range(1, len(lines)): lines[i] = lines[i][margin:] # Remove any trailing or leading blank lines. while lines and not lines[-1]: lines.pop() while lines and not lines[0]: lines.pop(0) return string.join(lines, '\n')
Example #21
Source File: inspect.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def indentsize(line): """Return the indent size, in spaces, at the start of a line of text.""" expline = string.expandtabs(line) return len(expline) - len(string.lstrip(expline))
Example #22
Source File: inspect.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def cleandoc(doc): """Clean up indentation from docstrings. Any whitespace that can be uniformly removed from the second line onwards is removed.""" try: lines = string.split(string.expandtabs(doc), '\n') except UnicodeError: return None else: # Find minimum indentation of any non-blank lines after first line. margin = sys.maxint for line in lines[1:]: content = len(string.lstrip(line)) if content: indent = len(line) - content margin = min(margin, indent) # Remove indentation. if lines: lines[0] = lines[0].lstrip() if margin < sys.maxint: for i in range(1, len(lines)): lines[i] = lines[i][margin:] # Remove any trailing or leading blank lines. while lines and not lines[-1]: lines.pop() while lines and not lines[0]: lines.pop(0) return string.join(lines, '\n')
Example #23
Source File: inspect.py From unity-python with MIT License | 5 votes |
def indentsize(line): """Return the indent size, in spaces, at the start of a line of text.""" expline = string.expandtabs(line) return len(expline) - len(string.lstrip(expline))
Example #24
Source File: inspect.py From unity-python with MIT License | 5 votes |
def cleandoc(doc): """Clean up indentation from docstrings. Any whitespace that can be uniformly removed from the second line onwards is removed.""" try: lines = string.split(string.expandtabs(doc), '\n') except UnicodeError: return None else: # Find minimum indentation of any non-blank lines after first line. margin = sys.maxint for line in lines[1:]: content = len(string.lstrip(line)) if content: indent = len(line) - content margin = min(margin, indent) # Remove indentation. if lines: lines[0] = lines[0].lstrip() if margin < sys.maxint: for i in range(1, len(lines)): lines[i] = lines[i][margin:] # Remove any trailing or leading blank lines. while lines and not lines[-1]: lines.pop() while lines and not lines[0]: lines.pop(0) return string.join(lines, '\n')
Example #25
Source File: inspect.py From canape with GNU General Public License v3.0 | 5 votes |
def indentsize(line): """Return the indent size, in spaces, at the start of a line of text.""" expline = string.expandtabs(line) return len(expline) - len(string.lstrip(expline))
Example #26
Source File: inspect.py From canape with GNU General Public License v3.0 | 5 votes |
def cleandoc(doc): """Clean up indentation from docstrings. Any whitespace that can be uniformly removed from the second line onwards is removed.""" try: lines = string.split(string.expandtabs(doc), '\n') except UnicodeError: return None else: # Find minimum indentation of any non-blank lines after first line. margin = sys.maxint for line in lines[1:]: content = len(string.lstrip(line)) if content: indent = len(line) - content margin = min(margin, indent) # Remove indentation. if lines: lines[0] = lines[0].lstrip() if margin < sys.maxint: for i in range(1, len(lines)): lines[i] = lines[i][margin:] # Remove any trailing or leading blank lines. while lines and not lines[-1]: lines.pop() while lines and not lines[0]: lines.pop(0) return string.join(lines, '\n')
Example #27
Source File: inspect.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def indentsize(line): """Return the indent size, in spaces, at the start of a line of text.""" expline = string.expandtabs(line) return len(expline) - len(string.lstrip(expline))
Example #28
Source File: inspect.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def cleandoc(doc): """Clean up indentation from docstrings. Any whitespace that can be uniformly removed from the second line onwards is removed.""" try: lines = string.split(string.expandtabs(doc), '\n') except UnicodeError: return None else: # Find minimum indentation of any non-blank lines after first line. margin = sys.maxint for line in lines[1:]: content = len(string.lstrip(line)) if content: indent = len(line) - content margin = min(margin, indent) # Remove indentation. if lines: lines[0] = lines[0].lstrip() if margin < sys.maxint: for i in range(1, len(lines)): lines[i] = lines[i][margin:] # Remove any trailing or leading blank lines. while lines and not lines[-1]: lines.pop() while lines and not lines[0]: lines.pop(0) return string.join(lines, '\n')
Example #29
Source File: inspect.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def cleandoc(doc): """Clean up indentation from docstrings. Any whitespace that can be uniformly removed from the second line onwards is removed.""" try: lines = string.split(string.expandtabs(doc), '\n') except UnicodeError: return None else: # Find minimum indentation of any non-blank lines after first line. margin = sys.maxint for line in lines[1:]: content = len(string.lstrip(line)) if content: indent = len(line) - content margin = min(margin, indent) # Remove indentation. if lines: lines[0] = lines[0].lstrip() if margin < sys.maxint: for i in range(1, len(lines)): lines[i] = lines[i][margin:] # Remove any trailing or leading blank lines. while lines and not lines[-1]: lines.pop() while lines and not lines[0]: lines.pop(0) return string.join(lines, '\n')
Example #30
Source File: XbmImagePlugin.py From keras-lambda with MIT License | 5 votes |
def _accept(prefix): return string.lstrip(prefix)[:7] == "#define" ## # Image plugin for X11 bitmaps.