• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python shlex.shlex函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中shlex.shlex函数的典型用法代码示例。如果您正苦于以下问题:Python shlex函数的具体用法?Python shlex怎么用?Python shlex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了shlex函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_new_data

def get_new_data(equity, last_date):
    date_splitter = shlex.shlex(last_date, posix=True)
    date_splitter.whitespace += '-'
    date_splitter.whitespace_split = True
    date = list(date_splitter)
    last_date = str(date[2]) + '/' + str(date[1]) + '/' + str(date[0]) 

    url = "http://www.bse-sofia.bg/graphics/phpfiles/MYgethistoDeA.php?MonCode=" + equity + "&MonPays=BE&Periode=1&De=" + last_date + "&A=" + datetime.date.today().strftime("%d/%m/%Y")     
    file_trades = urllib2.urlopen(url)
    tradedays = file_trades.readline()
    np_data = np.empty((0, 7))
    for line in file_trades: 
        if not line.strip():
            continue
        # split main line
        main_splitter = shlex.shlex(line.strip(), posix=True)
        main_splitter.whitespace += ';'
        main_splitter.whitespace_split = True
        trade = list(main_splitter)
        # if any trading for this day
        if trade[1] != 'N':
            # split date
            date_splitter = shlex.shlex(trade[0], posix=True)
            date_splitter.whitespace += '/'
            date_splitter.whitespace_split = True
            date = list(date_splitter)
            # "Date" , "Open", "High", "Low", "Close", Volumes"
            # 2012-12-21,10000,14046.26,1.423,1.4,1.4,1.423
            np_data = np.append(np_data, [[date[2] + "-" + date[1] + "-" + date[0], float(trade[1]) / 100, float(trade[2]) / 100, float(trade[3]) / 100, float(trade[4]) / 100, -1, trade[5]]], axis=0)
    return pand.DataFrame(data=np_data[:, 1:], index=np_data[:, 0], columns=("Open", "High", "Low", "Close", "AdjClose", "Volumes"), dtype=float)
开发者ID:dimitarm,项目名称:bse,代码行数:30,代码来源:bse-reader2.py


示例2: split

def split(string, maxsplit=-1):
    """ Split a string with shlex when possible, and add support for maxsplit. """
    if maxsplit == -1:
        try:
            split_object = shlex.shlex(string, posix=True)
            split_object.quotes = '"`'
            split_object.whitespace_split = True
            split_object.commenters = ""
            return list(split_object)
        except ValueError:
            return string.split()

    split_object = shlex.shlex(string, posix=True)
    split_object.quotes = '"`'
    split_object.whitespace_split = True
    split_object.commenters = ""
    maxsplit_object = []
    splits = 0

    while splits < maxsplit:
        maxsplit_object.append(next(split_object))

        splits += 1

    maxsplit_object.append(split_object.instream.read())

    return maxsplit_object
开发者ID:PcBoy111,项目名称:PCBOT,代码行数:27,代码来源:utils.py


示例3: _expand_args

def _expand_args(command):
    """Parses command strings and returns a Popen-ready list."""

    # Prepare arguments.
    if isinstance(command, STR_TYPES):
        if sys.version_info[0] == 2:
            splitter = shlex.shlex(command.encode('utf-8'))
        elif sys.version_info[0] == 3:
            splitter = shlex.shlex(command)
        else:
            splitter = shlex.shlex(command.encode('utf-8'))
        splitter.whitespace = '|'
        splitter.whitespace_split = True
        command = []

        while True:
            token = splitter.get_token()
            if token:
                command.append(token)
            else:
                break

        command = list(map(shlex.split, command))

    return command
开发者ID:TimexStudio,项目名称:pipenv,代码行数:25,代码来源:delegator.py


示例4: parse

    def parse(self, stream):
        if isinstance(stream, unicode):
            stream = stream.encode('utf-8')
        # Convert stream to StringIO if necessary
        stream = shlex.shlex(stream).instream
        # Create lexer, no data by default
        lex = shlex.shlex("", posix=True)
        lex.wordchars += "!$%&()*+-./:x<=>[email protected]:"
        lex.whitespace_split = False
        lex.quotes = '"'

        # Feed one line at the time
        lines = []
        prevline = []
        for raw in stream:
            lex.instream = shlex.StringIO(raw)
            lex.state = ' '
            newline = list(lex)
            withContinuation = (newline[-1] == '\n') if newline else False
            if withContinuation:
                newline.pop()
            if prevline:
                prevline.extend(newline)
                if not withContinuation:
                    prevline = []
                continue
            if withContinuation:
                prevline = newline
            lines.append(newline)
        # Filter out empty lines
        for line in lines:
            if not line:
                continue
            self.parseLine(line)
        return self
开发者ID:pombredanne,项目名称:jobslave,代码行数:35,代码来源:docker.py


示例5: fetch_devices_for_host

def fetch_devices_for_host(host):
    """A successful search returns a list of theano devices' string values.
    An unsuccessful search raises a KeyError.

    The (decreasing) priority order is:
    - PLATOON_DEVICES
    - PLATOONRC files (if they exist) from right to left
    - working directory's ./.platoonrc
    - ~/.platoonrc

    """
    # first try to have PLATOON_DEVICES
    if PLATOON_DEVICES:
        splitter = shlex.shlex(PLATOON_DEVICES, posix=True)
        splitter.whitespace += ','
        splitter.whitespace_split = True
        return list(splitter)

    # next try to find it in the config file
    try:
        try:
            devices = platoon_cfg.get("devices", host)
        except ConfigParser.InterpolationError:
            devices = platoon_raw_cfg.get("devices", host)
    except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
        raise KeyError(host)
    splitter = shlex.shlex(devices, posix=True)
    splitter.whitespace += ','
    splitter.whitespace_split = True
    return list(splitter)
开发者ID:mila-udem,项目名称:platoon,代码行数:30,代码来源:configparser.py


示例6: fetch_hosts

def fetch_hosts():
    """A successful search returns a list of host to participate in a multi-node
    platoon. An unsuccessful search raises a KeyError.

    The (decreasing) priority order is:
    - PLATOON_HOSTS
    - PLATOONRC files (if they exist) from right to left
    - working directory's ./.platoonrc
    - ~/.platoonrc

    """
    # first try to have PLATOON_HOSTS
    if PLATOON_HOSTS:
        splitter = shlex.shlex(PLATOON_HOSTS, posix=True)
        splitter.whitespace += ','
        splitter.whitespace_split = True
        return list(splitter)

    # next try to find it in the config file
    try:
        try:
            hosts = platoon_cfg.get("platoon", "hosts")
        except ConfigParser.InterpolationError:
            hosts = platoon_raw_cfg.get("platoon", "hosts")
    except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
        raise KeyError("hosts")
    splitter = shlex.shlex(hosts, posix=True)
    splitter.whitespace += ','
    splitter.whitespace_split = True
    return list(splitter)
开发者ID:mila-udem,项目名称:platoon,代码行数:30,代码来源:configparser.py


示例7: testPunctuationWithPosix

 def testPunctuationWithPosix(self):
     """Test that punctuation_chars and posix behave correctly together."""
     # see Issue #29132
     s = shlex.shlex('f >"abc"', posix=True, punctuation_chars=True)
     self.assertEqual(list(s), ['f', '>', 'abc'])
     s = shlex.shlex('f >\\"abc\\"', posix=True, punctuation_chars=True)
     self.assertEqual(list(s), ['f', '>', '"abc"'])
开发者ID:1st1,项目名称:cpython,代码行数:7,代码来源:test_shlex.py


示例8: split_ids

def split_ids(q):
    '''split input query string into list of ids.
       any of " \t\n\x0b\x0c\r|,+" as the separator,
        but perserving a phrase if quoted
        (either single or double quoted)
        more detailed rules see:
        http://docs.python.org/2/library/shlex.html#parsing-rules
        e.g. split_ids('CDK2 CDK3') --> ['CDK2', 'CDK3']
             split_ids('"CDK2 CDK3"\n CDk4')  --> ['CDK2 CDK3', 'CDK4']
    '''
    # Python3 strings are already unicode, .encode
    # now returns a bytearray, which cannot be searched with
    # shlex.  For now, do this terrible thing until we discuss
    if sys.version_info.major == 3:
        lex = shlex(q, posix=True)
    else:
        lex = shlex(q.encode('utf8'), posix=True)
    lex.whitespace = ' \t\n\x0b\x0c\r|,+'
    lex.whitespace_split = True
    lex.commenters = ''
    if sys.version_info.major == 3:
        ids = [x.strip() for x in list(lex)]
    else:
        ids = [x.decode('utf8').strip() for x in list(lex)]
    ids = [x for x in ids if x]
    return ids
开发者ID:SuLab,项目名称:myvariant.info,代码行数:26,代码来源:common.py


示例9: __init__

 def __init__(self, instream=None):
     if instream is not None:
         self._lexer = shlex.shlex(instream, posix=True)
     else:
         self._lexer = shlex.shlex(posix=True)
     self._lexer.whitespace += ','
     self._lexer.wordchars += './()*-$'
     self.eof = self._lexer.eof
开发者ID:dagss,项目名称:Bento,代码行数:8,代码来源:parse_utils.py


示例10: parse_load

	def parse_load(self, context, line, cursor):
		if context.template:
			self.warning(context, "load directives are not expected inside template definitions")

		cursor, _ = self.parse_space(context, line, cursor)
		cursor, path = self.parse_quoted(context, "'\"", "", line, cursor)
		if not path:
			raise Parse_Exception(context, "expected load path")

		cursor, _ = self.parse_literal_req(context, "as", line, cursor)
		cursor, alias = self.parse_identifier_req(context, line, cursor)

		cursor, _ = self.parse_space(context, line, cursor)
		params = []
		cursor, params_text = self.parse_paren(context, "", line, cursor)

		param_map = {
			"path" : path,
			"abs" : False,
			"directive_token" : self.directive_token,
			"placeholder" : self.placeholder
		}

		if params_text:
			# split by comma, preserve quotes
			comma_lex = shlex.shlex(params_text)
			comma_lex.whitespace_split = True
			comma_lex.whitespace = ","
			comma_lex.commenters = ""

			for param in comma_lex:
				# split by eq, strip quotes
				eq_lex = shlex.shlex(param, posix = True)
				eq_lex.whitespace_split = True
				eq_lex.whitespace += "="
				eq_lex.commenters = ""
				pair = list(eq_lex)
				key = pair[0].strip()
				value = True

				if len(pair) > 1:
					value = pair[1].strip()

				param_map[key] = value

		load = Template_Load()
		load.alias = alias
		load.path = param_map["path"]
		load.abs = param_map["abs"]
		load.directive_token = param_map["directive_token"]
		load.placeholder = param_map["placeholder"]

		self.trace(context,
			"load directive: {} as {}, abs({}), directive_token({}), placeholder({})".format(
			load.path, alias, load.abs, load.directive_token, load.placeholder))

		context.module.template_loads.append(load)
开发者ID:ramast,项目名称:jscomponent,代码行数:57,代码来源:parser.py


示例11: parse

    def parse(cls, string, context=None):
        """Parse a command string as usually is typed in console
            to create a :class`Planner`.

        :param `string`: the command line search to be parsed, using the
            mole search syntax.
        :param `context`: a dictionary to use as context for all actions.
            Usually you want to use context to pass arguments to actions in
            execution time.
        """
        ret = cls()
        shl = shlex.shlex(string)
        shl.wordchars += ("\t "+RESERVED)
        shl.whitespace = '|'

        if context is None:
            context = AttrDict({})

        for cmd in shl:
            cmd = " ".join(filter(lambda x:x not in KEYWORDS, cmd.split()))

            if len(cmd) == 0:
                continue

            args = []
            kwargs = {}

            ishl = shlex.shlex(cmd)
            ishl.wordchars += RESERVED

            cmd = [ x.strip("\"").strip("'") for x in ishl ]

            for arg in cmd[1:]:
                if "=" in arg:
                    kwargs.update(dict([tuple(arg.split("="))]))
                elif "," in arg:
                    args.append(arg.split(","))
                else:
                    args.append([arg])

            x = Action.from_type(cmd[0], *args, **kwargs)
            x.context = AttrDict(context)
            ret.add(x)

        if isinstance(ret.queue[0], ActionInput) and x.context is not None:
            obj = ret.queue[0].get_object()
            if obj is not None:
                if "plotter" in obj:
                    ret.add(obj.plotter)
                else:
                    ret.add(Plotter.from_type("basic"))
                if "parser" in obj:
                    ret.add(obj.parser)
                else:
                    ret.add(Parser.from_type("basic"))

        return ret
开发者ID:ajdiaz,项目名称:mole,代码行数:57,代码来源:planner.py


示例12: __init__

    def __init__( self, f, prompts=['~# ', '~$ '], com='', whi='' ):

        r"""
        The constructor takes a filename or an open file or a string
        as the shell session.

        The constructor sets the :attr:`tokens` member attribute with
        a shlex token stream initialised with the correct options for
        parsing comments and whitespace.
        
        The token commenters and whitespace are set to the empty string
        and can be modified with the function arguments 'com' and
        'whi'. 

        If the argument shlex_object is set to True then it'is not the
        list of tokens but the shlex object itself so that you can
        experiment with the :obj:`shlex` and it multiple attribute and
        method.

        >>> list(ShellSessionParser( "Yozza 1 2" ).tokens)
        ['Yozza', ' ', '1', ' ', '2']
        
        >>> tokens = ShellSessionParser( "Yozza 1 2").tokens
        >>> tokens.whitespace = ' '
        >>> list(tokens)
        ['Yozza', '1', '2']

        >>> list( ShellSessionParser("Yozza # a comment you dont want to see", whi=' ', com='#' ).tokens)
        ['Yozza']
        
        """
        
        self.tokens = shlex( f if hasattr(f, "read") else StringIO( f )) 
        self.tokens.commenters = com 
        # deactivate shlex comments facility which won't work for us.
        # The terminating linefeed means two things: end of comment an
        # end of command. As shlex consume the terminating linefeed,
        # there is no end of command left.
    
        self.tokens.whitespace = whi
        # deactivate shlex whitespace munging. characters cited in
        # ``shlex.whitespace`` are not returned by get_token. If
        # empty, whitespaces are returned as they are which is what we
        # want: they definitely count in bash, and may count in
        # output, so we just want to keep them as they are.

        self.nested = 0

        self.prompts = []
        for p in prompts:
            s=shlex(p)
            s.commenters, s.whitespace = com, whi
            self.prompts.append( list( s ) )

        self.max_prompt_len = max([ len(p) for p in self.prompts ])
开发者ID:jdb,项目名称:wordish,代码行数:55,代码来源:wordish.py


示例13: testEmptyStringHandling

 def testEmptyStringHandling(self):
     """Test that parsing of empty strings is correctly handled."""
     # see Issue #21999
     expected = ['', ')', 'abc']
     for punct in (False, True):
         s = shlex.shlex("'')abc", posix=True, punctuation_chars=punct)
         slist = list(s)
         self.assertEqual(slist, expected)
     expected = ["''", ')', 'abc']
     s = shlex.shlex("'')abc", punctuation_chars=True)
     self.assertEqual(list(s), expected)
开发者ID:cherish3620,项目名称:cpython,代码行数:11,代码来源:test_shlex.py


示例14: testPunctuationWithWhitespaceSplit

 def testPunctuationWithWhitespaceSplit(self):
     """Test that with whitespace_split, behaviour is as expected"""
     s = shlex.shlex('a  && b  ||  c', punctuation_chars='&')
     # whitespace_split is False, so splitting will be based on
     # punctuation_chars
     self.assertEqual(list(s), ['a', '&&', 'b', '|', '|', 'c'])
     s = shlex.shlex('a  && b  ||  c', punctuation_chars='&')
     s.whitespace_split = True
     # whitespace_split is True, so splitting will be based on
     # white space
     self.assertEqual(list(s), ['a', '&&', 'b', '||', 'c'])
开发者ID:cherish3620,项目名称:cpython,代码行数:11,代码来源:test_shlex.py


示例15: stream_video

def stream_video(url, open_chat):
    global screen, play_process, stream_quality, stream_chat, DEVNULL

    os.chdir(files_path)
    command = stream_command + " " + url + " " + stream_quality
    if stream_player != "":
        command = command + " --player " + stream_player

    lex = shlex.shlex(command)
    lex.whitespace_split = True
    args = list(lex)
    try:
        screen.clear()
        screen.refresh()

        set_status("starting stream")

        if stream_chat and open_chat:
            chat_command = "xdg-open " + url + "/chat"
            chat_lex = shlex.shlex(chat_command)
            chat_lex.whitespace_split = True
            chat_args = list(chat_lex)

            chat_process = subprocess.Popen(chat_args, stderr=DEVNULL)
            chat_process.wait()

        lex = shlex.shlex(command)
        lex.whitespace_split = True
        args = list(lex)

        play_process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        while True:
            line = play_process.stdout.readline()
            if not line:
                break
            set_status(line.decode("utf-8"))
            logging.debug(line)

        play_process.wait()

        set_status("finished stream")
        play_process = None

        restore_state()

    except:

        set_status("playback failed")
        play_process = None

        restore_state()
        return 1

    return 0
开发者ID:jazztickets,项目名称:redpi,代码行数:54,代码来源:redpi.py


示例16: get_adj_close_data

def get_adj_close_data(equity):
    url2 = "http://www.bse-sofia.bg/?page=ExportData&target=security&code=" + equity 
    print url2
    fl_url = urllib2.urlopen(url2)
    fl_url.read(3)  # read BOM
    trades = list()
    sym = fl_url.read(1)
    day_data = str()
    while sym:
        if sym == '\n':
            trades.append(day_data)
            day_data = str()
        elif sym == 'E':
            of = fl_url.read(4)
            if of == '\x00O\x00F':
                trades.append(day_data)
                day_data = str()
                break;
            day_data += sym
            day_data == of
        else:
            day_data += sym
        sym = fl_url.read(1)
    if day_data:
        trades.append(day_data)
    
    np_data = np.empty((0, 7))
    for trade in trades:
        trade = trade[:-3]  # remove \x00\r\x00 at the end
        trade, b = decodefunc(trade)
        trade = trade.strip()
        if not trade:
            continue
    # split main line
        main_splitter = shlex.shlex(trade, posix=True)
        main_splitter.whitespace += ';'
        main_splitter.whitespace_split = True
        trade = list(main_splitter)
        # ['13.11.11', '3.348', '3.379', '9129', '11.51', '10.86', '8.17', '5.23', '1.85', '.59', '1.15', '1.1']
        # split date
        # trade[0] date
        # trade[1] adjusted close
        # trade[2] close
        # trade[3] volume
        if trade:
            date_splitter = shlex.shlex(trade[0], posix=True)
            date_splitter.whitespace += '.'
            date_splitter.whitespace_split = True
            date = list(date_splitter)
            date = str('20' + str(date[0] + '-' + date[1]) + '-' + str(date[2])) 
            np_data = np.append(np_data, values=[[date, float(0), float(0), float(0), float(trade[2]), float(trade[1]), float(trade[3])]], axis=0)
    fl_url.close()
    return pand.DataFrame(data=np_data[:, 1:], index=np_data[:, 0], columns=("Open", "High", "Low", "Close", "AdjClose", "Volumes"), dtype=float) 
开发者ID:dimitarm,项目名称:bse,代码行数:53,代码来源:bse-reader2.py


示例17: __init__

    def __init__(self, path, data=None):
        ConsoleP.__init__(self, 'pkgbuild')

        if path is None:
            self.eval = shlex.shlex(data, posix=True)
        else:
            self.eval = shlex.shlex(open(path, "r").read(), posix=True)

        self.eval.whitespace = " \t"
        self.eval.wordchars += '.:/${}-~'
        self.eval.commenters = '#'
        self.state = self.ST_VAR
        self.scope = Scope()

        self.parse()
开发者ID:godane,项目名称:archiso-live,代码行数:15,代码来源:pkgbuild.py


示例18: rename_window

    def rename_window(self, new_name):
        """Return :class:`Window` object ``$ tmux rename-window <new_name>``.

        :param new_name: name of the window
        :type new_name: string

        """

        import shlex
        lex = shlex.shlex(new_name)
        lex.escape = ' '
        lex.whitespace_split = False

        try:
            self.cmd(
                'rename-window',
                new_name
            )
            self['window_name'] = new_name
        except Exception as e:
            logger.error(e)

        self.server._update_windows()

        return self
开发者ID:markoantolos,项目名称:tmuxp,代码行数:25,代码来源:window.py


示例19: shlex_quotes

def shlex_quotes(value):
    '''see http://stackoverflow.com/questions/6868382/python-shlex-split-ignore-single-quotes'''
    lex = shlex.shlex(value)
    lex.quotes = '"'
    lex.whitespace_split = True
    lex.commenters = ''
    return list(lex)
开发者ID:krzysiu4,项目名称:MAVProxy,代码行数:7,代码来源:mavproxy.py


示例20: parse

 def parse(self, path):
     errs = 0
     def check(name, mapping, listname):
         if name in mapping:
             self.ui.warn(_('%s:%d: %r already in %s list\n') %
                          (lex.infile, lex.lineno, name, listname))
             return 1
         return 0
     lex = shlex.shlex(open(path), path, True)
     lex.wordchars += '[email protected]#$%^&*()-=+[]{}|;:,./<>?'
     cmd = lex.get_token()
     while cmd:
         if cmd == 'include':
             name = lex.get_token()
             errs += check(name, self.exclude, 'exclude')
             self.include[name] = name
         elif cmd == 'exclude':
             name = lex.get_token()
             errs += check(name, self.include, 'include')
             errs += check(name, self.rename, 'rename')
             self.exclude[name] = name
         elif cmd == 'rename':
             src = lex.get_token()
             dest = lex.get_token()
             errs += check(src, self.exclude, 'exclude')
             self.rename[src] = dest
         elif cmd == 'source':
             errs += self.parse(lex.get_token())
         else:
             self.ui.warn(_('%s:%d: unknown directive %r\n') %
                          (lex.infile, lex.lineno, cmd))
             errs += 1
         cmd = lex.get_token()
     return errs
开发者ID:c0ns0le,项目名称:cygwin,代码行数:34,代码来源:filemap.py



注:本文中的shlex.shlex函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python shlex.shlex_split函数代码示例发布时间:2022-05-27
下一篇:
Python shlex.quote函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap