GVKun编程网logo

Python: instant markup -- an extensible impleme...

1

针对Python:instantmarkup--anextensibleimpleme...这个问题,本篇文章进行了详细的解答,同时本文还将给你拓展(OK)NCTUns(EstiNet)---ahig

针对Python: instant markup -- an extensible impleme...这个问题,本篇文章进行了详细的解答,同时本文还将给你拓展(OK) NCTUns (EstiNet) --- a high-fidelity and extensible network simulator and emulator、ABAP XSLT(Extensible Stylesheet Language Transformation)、after markup mount - how is converted source code got executed、Angular 2 Markup – 如果String为Empty,则显示其他内容等相关知识,希望可以帮助到你。

本文目录一览:

Python: instant markup -- an extensible impleme...

Python: instant markup -- an extensible impleme...

#!/usr/bin/env python
import sys, re
from handlers import *
from util import *
from rules import *

class Parser:
    """
    A Parser reads a text file, applying rules and controlling a
    handler.
    """
    def __init__(self, handler):
        self.handler = handler
        self.rules = []
        self.filters = []
    def addRule(self, rule):
        self.rules.append(rule)
    def addFilter(self, pattern, name):
        def filter(block, handler):
            return re.sub(pattern, handler.sub(name), block)
        self.filters.append(filter)
    def parse(self, file):
        # read ahead, the first line is assumed to be the docname
        docname = file.readline() or ''...''
        self.handler.start(''document'', docname)
        file.seek(0)
        for block in blocks(file):
            for filter in self.filters:
                block = filter(block, self.handler)
            for rule in self.rules:
                if rule.condition(block):
                    last = rule.action(block, self.handler)
                    if last: break
        self.handler.end(''document'')

class BasicTextParser(Parser):
    """
    A specific Parser that adds rules and filters in its
    constructor.
    """
    def __init__(self, handler):
        Parser.__init__(self, handler)
        self.addRule(ListRule())
        self.addRule(ListItemRule())
        self.addRule(TitleRule())
        self.addRule(HeadingRule())
        self.addRule(ParagraphRule())
        self.addFilter(r''\*(.+?)\*'', ''emphasis'')
        self.addFilter(r''(http://[\.a-zA-Z/]+)'', ''url'')
        self.addFilter(r''([\.a-zA-Z]+@[\.a-zA-Z]+[a-zA-Z]+)'', ''mail'')



if __name__ == ''__main__'':
    handler = HTMLRenderer()
    parser = BasicTextParser(handler)
    parser.parse(sys.stdin)
class Handler:
    """
    An object that handles method calls from the Parser.
    The Parser will call the start() and end() methods at the
    beginning of each block, with the proper block name as a
    parameter. The sub() method will be used in regular expression
    substitution. When called with a name such as ''emphasis'', it will
    return a proper substitution function.
    """
    def callback(self, prefix, name, *args):
        method = getattr(self, prefix+name, None)
        if callable(method): return method(*args)
    def start(self, name, arg=None):
        if arg == None:
            self.callback(''start_'', name)
        else:
            self.callback(''start_'', name, arg)
    def end(self, name):
        self.callback(''end_'', name)
    def sub(self, name):
        def substitution(match):
            result = self.callback(''sub_'', name, match)
            if result is None: match.group(0)
            return result
        return substitution

class HTMLRenderer(Handler):
    """
    A specific handler used for rendering HTML.
    The methods in HTMLRenderer are accessed from the superclass
    Handler''s start(), end(), and sub() methods. They implement basic
    markup as used in HTML documents.
    """
    def start_document(self, docname=''...''):
        print ''<html><head><title>''+docname+''</title></head><body>''
    def end_document(self):
        print ''</body></html>''
    def start_paragraph(self):
        print ''<p>''
    def end_paragraph(self):
        print ''</p>''
    def start_heading(self):
        print ''<h2>''
    def end_heading(self):
        print ''</h2>''
    def start_list(self):
        print ''<ul>''
    def end_list(self):
        print ''</ul>''
    def start_listitem(self):
        print ''<li>''
    def end_listitem(self):
        print ''</li>''
    def start_title(self):
        print ''<h1>''
    def end_title(self):
        print ''</h1>''
    def sub_emphasis(self, match):
        return ''<em>%s</em>'' % match.group(1)
    def sub_url(self, match):
        return ''<a href="%s">%s</a>'' % (match.group(1), match.group(1))
    def sub_mail(self, match):
        return ''<a href="mailto:%s">%s</a>'' % (match.group(1), match.group(1))
    def feed(self, data):
        print data
class Rule:
    """
    Base class for all rules.
    """
    def action(self, block, handler):
        handler.start(self.type)
        handler.feed(block)
        handler.end(self.type)
        return True

class HeadingRule(Rule):
    """
    A heading is a single line that is at most 70 characters and
    that doesn''t end with a colon.
    """
    type = ''heading''
    def condition(self, block):
        return not ''\n'' in block and len(block) <= 70 and not block[-1] == '':''

class TitleRule(HeadingRule):
    """
    The title is the first block in the document, provided that it is
    a heading.
    """
    type = ''title''
    first = True
    def condition(self, block):
        if not self.first: return False
        self.first = False
        return HeadingRule.condition(self, block)

class ListItemRule(Rule):
    """
    A list item is a paragraph that begins with a hyphen. As part of
    the formatting, the hyphen is removed.
    """
    type = ''listitem''
    def condition(self, block):
        return block[0] == ''-''
    def action(self, block, handler):
        handler.start(self.type)
        handler.feed(block[1:].strip())
        handler.end(self.type)
        return True


class ListRule(ListItemRule):
    """
    A list begins between a block that is not a list item and a
    subsequent list item. It ends after the last consecutive list
    item.
    """
    type = ''list''
    inside = False
    def condition(self, block):
        return True
    def action(self, block, handler):
        if not self.inside and ListItemRule.condition(self, block):
            handler.start(self.type)
            self.inside = True
        elif self.inside and not ListItemRule.condition(self, block):
            handler.end(self.type)
            self.inside = False
        return False

class ParagraphRule(Rule):
    """
    A paragraph is simply a block that isn''t covered by any of the
    other rules.
    """
    type = ''paragraph''
    def condition(self, block):
        return True
#!/usr/bin/env python
import sys
def lines(f):
    for line in f: yield line
    yield ''\n''

def blocks(f):
    block = []
    for line in lines(f):
        if line.strip():
            block.append(line)
        elif block:
            yield ''''.join(block).strip()
            block = []


def test():
    if len(sys.argv) <= 1:
        print ''argument not correct''
    else:
        # print blocks in the file
        with open(sys.argv[1]) as f:
            i = 1
            for block in blocks(f):
                print ''[block#%d]'' % i
                print block
                i += 1

if __name__ == ''__main__'':
    test()

 

 

 

 

 

 

 

(OK) NCTUns (EstiNet) --- a high-fidelity and extensible network simulator and emulator

(OK) NCTUns (EstiNet) --- a high-fidelity and extensible network simulator and emulator


http://blog.sciencenet.cn/blog-388967-570863.html


今天看到一个仿真与模拟软件NCTUns(http://csie.nqu.edu.tw/smallko/nctuns/nctuns.htm),可惜只免费到到6.0,以后的版本因为该软件的成功而升级为商业版本--EstiNet7.0,且不再提供老版本的免费下载。从该网站的介绍看,该软件还是不错的,可以提供以下几方面的功能,某些方面可以说比NS2/OPNet要方便,不足的地方就是只“完美”支持Fedora12(虽然也有在Ubuntu下做的,不过问题不少!),且在应用层能支持的东东不是很多,权且收下,抽空好好看看。


NCTUns(http://csie.nqu.edu.tw/smallko/nctuns/nctuns.htm)

EstiNet7.0

(2)Introduction:

TheNCTUns is a high-fidelity and extensible network simulator and emulator capableof simulating various protocols used in both wired and wireless IP networks. Its core technology is basedon the novel kernel re-entering methodology invented by Prof. S.Y. Wang [1, 2]when he was pursuing his Ph.D. degree at Harvard University.Due to this novel methodology, NCTUns provides many unique advantages thatcannot be easily achieved by traditional network simulators such as ns-2 [3]and OPNET [4].

After obtaining hisPh.D. degree from Harvard University in September 1999, Prof. S.Y. Wangreturned to Taiwan and became a professor in the Department of ComputerScience, National Chiao Tung University (NCTU), Taiwan, where he founded his“Network and System Laboratory.” Since that time, Prof. S.Y. Wang has beenleading and working with his students to design and implement NCTUns (the NCTUNetwork Simulator) for more than nine years. 

The NCTUns networksimulator and emulator has many useful features listed below:

·        It can be easily used as anemulator. An external host in the real world canexchange packets (e.g., set up a TCP connection) with nodes (e.g., host,router, or mobile station) in a network simulated by NCTUns. Two external hostsin the real world can also exchange their packets via a network simulated byNCTUns. This feature is very useful as the function and performance ofreal-world devices can be tested under various simulated network conditions.

·        It supports distributedemulation of a large network over multiple machines.When the emulated network has many nodes,many real-world applications need to run on these nodes, many real-worlddevices need to connect to the emulated network, or the amount of real-worldpackets exchanged among real-world devices over the emulated network is large,a single machine may not have enough CPU power and main memory to run theemulation in real time. In such a condition, NCTUns can partition the emulatednetwork into several smaller parts and let each part be emulated by a NCTUnsmachine. The usage of a distributed emulation is totally automatic and the userwon’t notice that the emulation is carried out over multiple machines.

·        It supports seamless integrationof emulation and simulation. A complicatednetwork simulated by NCTUns can be seamlessly integrated with a real-lifenetwork. Real-life network traffic can pass through a complicated simulatednetwork and interact with simulated network traffic.

·        It directly uses the real-lifeLinux TCP/IP protocol stack to generate high-fidelity simulation results. By using a novel kernel re-enteringsimulation methodology, a real-life Linux kernel’s protocol stack is directlyused to generate high-fidelity simulation results.

·        It can run any real-life UNIXapplication program on a simulated node without any modification. Any real-life program (e.g., P2P BitTorrent or Javaprograms) can be run on a simulated host, router, mobile node, etc. to generaterealistic network traffic. This capability also enables a researcher toevaluate the functionality and performance of a distributed application orsystem under various network conditions. Another important advantage of thisfeature is that application programs developed during simulation studies can bedirectly deployed and run on real-world UNIX machines after simulation studiesare finished. This eliminates the time and effort required to port a simulationprototype to a real-world implementation if traditional network simulators wereused.

·        It can use any real-life UNIXnetwork configuration and monitoring tools. For example, the UNIX route, ifconfig, netstat,tcpdump, traceroute commands can be run on a simulated network to configure ormonitor the simulated network.

·        Its setup and usage of asimulated network and application programs are exactly the same as those usedin real-life IP networks.For example, each layer-3 interface has an IP address automatically assigned toit by the GUI and application programs directly use these IP addresses tocommunicate with each other. For this reason, any person who is familiar withreal-life IP networks will easily learn and operate NCTUns in just a fewminutes. For the same reason, NCTUns can be used as an educational tool toteach students how to configure and operate a real-life network. 

·        It simulates various importantnetworks. Thesupported networks include Ethernet-based fixed Internet, IEEE 802.11(b)wireless LANs, mobile ad hoc (sensor) networks, GPRS cellular networks, opticalnetworks (including both circuit-switching and busrt-switching networks), IEEE802.11(b) dual-radio wireless mesh networks, IEEE 802.11(e) QoS wireless LANs,Tactical and active mobile ad hoc networks, 3dB beamwidth 60-degree and90-degree steerable and directional antennas, IEEE 802.16(d) WiMAX wirelessnetworks (including the PMP and mesh modes), DVB-RCS satellite networks,wireless vehicular networks for Intelligent Transportation Systems (includingV2V and V2I), multi-interface mobile nodes for heterogeneous wireless networks,IEEE 802.16(e) mobile WiMAX networks, IEEE 802.11(p)/1609 WAVE wirelessvehicular networks, various realistic wireless channel models, IEEE 802.16(j)transparent mode and non-transparent mode WiMAX networks, etc. 

·        It simulates various importantprotocols. For example, IEEE 802.3 CSMA/CD MAC, IEEE802.11 (b) CSMA/CA MAC, IEEE 802.11(e) QoS MAC, IEEE 802.11(b) wireless meshnetwork routing protocol, IEEE 802.16(d)(e)( j) WiMAXwireless MAC and PHY, DVB-RCSsatellite MAC and PHY,learning bridge protocol, spanning tree protocol, IP, Mobile IP, Diffserv(QoS), RIP, OSPF, UDP, TCP, RTP/RTCP/SDP, HTTP, FTP, Telnet, BitTorrent, etc.

·        It finishes a network simulationcase quickly. By combining thekernel re-entering methodology with the discrete-event simulation methodology,a simulation job can be finished quickly.

·        It generates repeatablesimulation results.If the user fixes the random number seed for a simulation case, the simulationresults of a case are the same across different simulation runs even if thereare some other activities (e.g., disk I/O) occurring on the simulation machine.

·        It provides a highly-integratedand professional GUI environment.This GUI can help a user to quickly (1) draw network topologies, (2) configurethe protocol modules used inside a node, (3) specify the moving paths of mobilenodes, (4) plot network performance graphs, (5) play back the animation of alogged packet transfer trace, etc. All of these operations can be easily,intuitively, and quickly done with the GUI.

·        Its simulation engine adopts anopen-system architecture and is open source. By using a set of module APIs provided by thesimulation engine, a protocol developer can easily implement his (her) protocoland integrate it into the simulation engine. NCTUns uses a simple andeasy-to-understand syntax to describe the settings and configurations of asimulation job. These descriptions are generated by the GUI and stored in asuite of files. Normally the GUI will automatically transfer these files to thesimulation engine for execution. However, if a researcher wants to try his(her) novel device or network configurations that the current GUI does notsupport, he (she) can totally bypass the GUI and generate the suite ofdescription files by himself (herself) using any text editor (or scriptprogram). The non-GUI-generated suite of files can then be manually fed to thesimulation engine for execution.   

·        It supports remote andconcurrent simulations. NCTUns adopts adistributed architecture. The GUI and simulation engine are separatelyimplemented and use the client-server model to communicate. Therefore, a remoteuser using the GUI program can remotely submit his (her) simulation job to aserver running the simulation engine. The server will run the submittedsimulation job and later return the results back to the remote GUI program foranalyses. This scheme can easily support the cluster computing model in whichmultiple simulation jobs are performed in parallel on different servermachines. Thiscan increase the total simulation throughput.

·        It provides complete and high-qualitydocumentations. TheGUI user manual and the protocol developer manual provide detailed informationabout how to use NCTUns. The NCTUns package provides 83 example simulationcases and their demo video clips to help a user easily understand how to run upa simulation case.

·         It is continuously supported, maintained, and improved. New functions and network types arecontinuously added to NCTUns to enhance its functions, speed, and capabilities.

(3)Relatedpapers:

S.Y.Wang, and Y.M. Huang, “ NCTUns Distributed Network Emulator,” Internet Journal, Vol. 4, Num. 2, pp. 61-94, Nova Science Publisher (ISSN 1937-3805), 2012

 S.Y.Wang, P.F. Wang, Y.W. Li, and L.C. Lau, “Design and Implementation of A More Realistic Radio Propagation Model for WirelessVehicular Networks over the NCTUns Network Simulator,” IEEE WCNC 2011 (Wireless Communications and Networking Conference 2011),March 28 – 31, 2011, Cancun, Mexico.

 S.Y.Wang, C.C. Lin, and C.C. Huang, “NCTUnsTool for Evaluating the Performances of Real-life P2P Applications,” achapter of the “Peer-to-Peer Networksand Internet Policies” book, (ISBN 978-1-60876-287-3, published by Nova Science Publishers in 2010)

 S.Y. Wang, H.Y. Chen, and S.W.Chuang, “NCTUns Tool for IEEE 802.16j Mobile WiMAXRelay Network Simulations,” a chapter of the “Computer Science Research and Technology” book, (ISBN: 978-1-61728-688-9, published by Nova Science Publishers in 2009)

 S.Y. Wang and C.L. Chou, “NCTUns Tool for WirelessVehicular Communication Network Researches,” SimulationModelling Practice and Theory, Vol. 17, No. 7, pp. 1211-1226, August 2009.

 S.Y.Wang and R.M. Huang, “NCTUns Tool for Innovative NetworkEmulations,” a chapter of the “Computer-Aided Design and OtherComputing Research Developments” book, (ISBN: 978-1-60456-860-8, published by Nova Science Publishers in2009)

 S.Y. Wang and C.C. Lin, "NCTUns5.0: A Network Simulator for IEEE 802.11(p) and 1609 Wireless Vehicular NetworkResearches," 2nd IEEE International Symposium on Wireless VehicularCommunications, September 21–22, 2008, Calgary, Canada. (demo paper)

 S.Y. Wang and C.L.Chou, "NCTUns Simulator for Wireless Vehicular AdHoc Network Research", a chapter of the "Ad Hoc Networks: New Research"book (Nova Science Publishers,ISBN: 978-1-60456-895-0)

 S.M. Huang, Y.C.Sung, S.Y. Wang, and Y.B. Lin, “NCTUns Simulation Toolfor WiMAX Modeling,” Third Annual International Wireless InternetConference, October 22 – 24, 2007, Austin, Texas, USA. (EI and ISI indexed,sponsored by ICST, ACM, EURASIP)

 S.Y.Wang, C.L. Chou, Y.H. Chiu, Y.S.Tseng, M.S. Hsu, Y.W. Cheng, W.L. Liu, and T.W. Ho,“NCTUns 4.0: An Integrated SimulationPlatform for Vehicular Traffic, Communication, and Network Researches,”1st IEEE International Symposium on Wireless VehicularCommunications, September 30 – October 1, 2007, Baltimore, MD, USA

 S.Y. Wang,C.L. Chou, C.C. Lin, “The Design andImplementation of the NCTUns Network Simulation Engine”,Elsevier Simulation Modelling Practice and Theory, 15 (2007) 57 – 81.

 S.Y. Wang and K.C. Liao, “InnovativeNetwork Emulations using the NCTUns Tool”, as a book chapter of the “Computer Networking and Networks”book, (ISBN1-59454-830-7,publishedby Nova Science Publishers in 2006)

 S.Y. Wang and Y.B. Lin, “NCTUnsNetwork Simulation and Emulation for Wireless Resource Management”, WileyWireless Communications and Mobile Computing,Vol.5, Issue 8, December 2005, pp. 899–916.

 S.Y. Wang, C.L. Chou, C.H. Huang,C.C. Hwang, Z.M. Yang, C.C. Chiou, and C.C. Lin, "The Design andImplementation of the NCTUns 1.0 Network Simulator", ComputerNetworks, Vol. 42, Issue 2, June 2003, pp. 175-197.

 S.Y. Wang, “NCTUns 1.0”, in the column “Software Tools forNetworking”, IEEE Networks, Vol. 17, No. 4, July 2003.

 S.Y. Wang and H.T. Kung, "ANew Methodology for Easily Constructing Extensible and High-Fidelity TCP/IPNetwork Simulators", Computer Networks, Vol. 40, Issue 2, October2002, pp. 257-278.

 S.Y. Wang and H.T. Kung, "ASimple Methodology for Constructing Extensible and High-Fidelity TCP/IP NetworkSimulators", IEEE INFOCOM''99, March 21-25, 1999, New York, USA.



ABAP XSLT(Extensible Stylesheet Language Transformation)

ABAP XSLT(Extensible Stylesheet Language Transformation)

enables the conversion of XML formats into any other XML formats. The ABAP runtime environment contains an SAP XSLT processor for performing XSL transformations.

The source and result of a general XSL transformation are XML data. When an XSL transformation is called using the statement CALL TRANSFORMATION, however, ABAP data can also be transformed directly to XML and back. For this purpose, a serialization or deserialization is performed implicitly, with asXML as an intermediate format.

In the case of transformations that use ABAP data as a source, the ABAP data is first serialized to a canonical XML representation (asXML) with the predefined identity transformation ID. This intermediate result is then used as the actual source for the XSL transformation. If the transformation ID itself is called in CALL TRANSFORMATION, the intermediate result is in the direct output.

本文同步分享在 博客“汪子熙”(CSDN)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

after markup mount - how is converted source code got executed

after markup mount - how is converted source code got executed

Created by Wang, Jerry, last modified on Feb 21, 2016

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

本文分享 CSDN - 汪子熙。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

Angular 2 Markup – 如果String为Empty,则显示其他内容

Angular 2 Markup – 如果String为Empty,则显示其他内容

所以在AngularJS中,有一种方法,在标记中,将数据绑定到这样的字符串:

{{myString | 'N/A'}}

这样做,在一次快速滑动中,显示字符串,如果它不是空的.如果它是空的,它将显示管道后面的文本.

现在我正在使用Angular 2,我正在尝试做同样的事情,除了我似乎无法找到这样做的语法.有人试过这样做吗?如果是这样,我怎样才能在组件级别进行操作.

谢谢

解决方法

单个管道是 Bitwise OR被认为是Angular 2中的Pipe,它在|之后查找名称为filter的过滤器符号.你应该使用||而不是|(单管).

{{myString || 'N/A'}}

今天关于Python: instant markup -- an extensible impleme...的介绍到此结束,谢谢您的阅读,有关(OK) NCTUns (EstiNet) --- a high-fidelity and extensible network simulator and emulator、ABAP XSLT(Extensible Stylesheet Language Transformation)、after markup mount - how is converted source code got executed、Angular 2 Markup – 如果String为Empty,则显示其他内容等更多相关知识的信息可以在本站进行查询。

本文标签: